Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
03-10-2021 05:29 AM
I'm trying to define a map where one of the key values includes a hyphen. This is a very simple example:
WITH {non-production:'nonprod'} as envmap
return envmap
Doing this returns an error:
Invalid input '-': expected an identifier character, whitespace, '}' or ':' (line 1, column 10 (offset: 9))
"WITH {non-production:'nonprod'} as envmap"
This works fine when the key value does not require a hyphen, such as:
WITH {nonproduction:'nonprod'} as envmap
return envmap
But I need the hyphen in there. I've tried escaping the hyphen, such as:
WITH {non\-production:'nonprod'} as envmap
return envmap
But that still results in a syntax error, this time pointing at the escape character instead of at the hyphen. I tried with two escape sequence characters, same result. I thought perhaps trying to create another variable with that value then using the variable name might help, such as in:
WITH 'non-production' as np, {np:'nonprod'} as envmap
return envmap
While that gets rid of the syntax error, it uses 'np' as the key value, it does not use the value of the np variable.
How is a key value which contains a hyphen specified in a map?
Solved! Go to Solution.
03-10-2021 08:51 AM
You can do it with back ticks:
WITH {`non-production`:'nonprod'} as envmap
return envmap
03-10-2021 08:51 AM
You can do it with back ticks:
WITH {`non-production`:'nonprod'} as envmap
return envmap
03-10-2021 11:30 AM
Thank you Mark! That looks like it will work!
03-10-2021 08:52 AM
Enclose non-production between backticks;
WITH {`non-production`:'nonprod'} as envmap
return envmap
03-10-2021 11:29 AM
Thank you! That looks like it will do it!
All the sessions of the conference are now available online