简体   繁体   English

如何使用变量动态创建 Neo4j/Cypher 标签?

[英]How to creating Neo4j/Cypher labels dynamically with variable?

When I try:当我尝试:

CALL apoc.load.jdbc('jdbc:mysql://localhost/mysql?user=root&password=root&useUnicode=true&characterEncoding=utf8','select * from db')YIELD row
WHERE row.label = 'dis' MERGE (n:dis {name: row.keyword})
WHERE row.label = 'part' MERGE (n:part {name: row.keyword})

and there is an error并且有一个错误

Neo.ClientError.Statement.SyntaxError: Invalid input 'H': expected 'i/I'

you can use the apoc fucntions to do this您可以使用 apoc 功能来执行此操作

CALL apoc.merge.node(['Label'], identProps:{key:value, …​}, onCreateProps:{key:value,…​}, onMatchProps:{key:value,…​}})

the following query will dynamically read label names and merge nodes with respective label以下查询将动态读取标签名称并合并具有相应标签的节点

CALL apoc.load.jdbc('jdbc:mysql://localhost/mysql?user=root&password=root&useUnicode=true&characterEncoding=utf8','select * from db')YIELD row 
CALL apoc.merge.node([row.label], identProps:{name:row.keyword}, onCreateProps:{}, onMatchProps:{}}) YIELD node 
RETURN node 

If you intend to match node with specific label, you should probably use the MATCH (:label) clause instead of WHERE label = ...如果您打算匹配具有特定标签的节点,您可能应该使用MATCH (:label)子句而不是WHERE label = ...

CALL apoc.load.jdbc('jdbc:mysql://localhost/mysql?user=root&password=root&useUnicode=true&characterEncoding=utf8','select * from db')YIELD row
OPTIONAL MATCH (row:dis) MERGE (n:dis {name: row.keyword})
OPTIONAL MATCH (row:part) MERGE (n:part {name: row.keyword})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM