Thursday, September 21, 2017

How to Create a Cypher Map With Dynamic Keys

DZone Database Zone
How to Create a Cypher Map With Dynamic Keys
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:

Fun With SQL: Functions in Postgres

DZone Database Zone Fun With SQL: Functions in Postgres In our previous  Fun with SQL  post on the  Citus Data  blog, we covered w...