DZone Database Zone
How to Create a Cypher Map With Dynamic Keys
I was recently trying to create a map in a Cypher query but wanted to have dynamic keys in that map. I started off with this query:
WITH "a" as dynamicKey, "b" as dynamicValue
RETURN { dynamicKey: dynamicValue } AS map
╒══════════════════╕
│"map" │
╞══════════════════╡
│{"dynamicKey":"b"}│
└──────────────────┘
Not quite what we want! We want dynamicKey to be evaluated rather than treated as a literal. As usual, APOC comes to the rescue!
No comments:
Post a Comment