Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
7.2k views
in Technique[技术] by (71.8m points)

neo4j - apoc.merge.node with special identifier fails

I tried to merge a node with apoc.merge.node but my ident property keys have a special char(:) and get double escaped. Did i miss something or does a workaround exist? If i replace the ":" with "_" everything works as expected.

Neo4j 4.2.1 community and APOC 4.2.0

CALL apoc.merge.node(["test"], apoc.map.fromPairs([["i:d","123"]])) YIELD node return node

Error

Failed to invoke procedure `apoc.merge.node`: Caused by: org.neo4j.exceptions.SyntaxException: Invalid input 'i': expected "}" (line 1, column 17 (offset: 16))
"MERGE (n:test{``i:d``:$identProps.``i:d``}) ON CREATE SET n += $onCreateProps ON MATCH SET n += $onMatchProps RETURN n"
question from:https://stackoverflow.com/questions/65850959/apoc-merge-node-with-special-identifier-fails

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

EDIT

It seems there is a bug in APOC which causes the identifier to be encoded twice.

First with Util::quote https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4.1/core/src/main/java/apoc/util/Util.java#L674

And then in the merge procedure https://github.com/neo4j-contrib/neo4j-apoc-procedures/blob/4.1/core/src/main/java/apoc/merge/Merge.java#L85

I've filed an issue: https://github.com/neo4j-contrib/neo4j-apoc-procedures/issues/1783


In Neo4j, you can use backticks ` around a key that contain special characters :

CALL apoc.merge.node(["test"], apoc.map.fromPairs([["`i:d`","123"]])) 
YIELD node 
return node

Same is true everywhere in the Cypher syntax, escaping a label with a whitespace for eg :

MERGE (n:`Land Vehicle` {id: "land-rover-1"})

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...