Reputation: 180
I can set parameters as arrays and other data types with the syntax
:param x => ["some Data", "other data"
:param y => 5
:param z => "Hello"
But doing this yields an error
:param someObject => {
data:"something"
moreData:"something else"
}
Error:
Invalid input 'd': expected whitespace or a label name
I've been unable to find any documentation that goes into parameters in depth so I have no clue what the syntax should be here. It seems to expect a query when I use curly braces
Upvotes: 0
Views: 504
Reputation: 180
There isn't any documentation on the website but there is very helpful documentation inside when using the :help command in the browser. Specifically :help params
cybersam's answer works but needs but doesn't fully explain what's going on and is based on the older syntax. The right hand of => is evaluated as Cypher and an implicit RETURN
is placed in front. Therefore:
:param x => 4
can be expressed explicitly as
:param [{x}] => { RETURN 4 as x }
When explicitly setting a param the express on the right has to be wrapped in{}
with RETURN
explicitly placed in front of the expression inside. This was the issue with the query in the question. Nothing is returned inside of {}
so an error gets thrown.
Additionally the results have to be destructured in this format [{x, y, z}]
and I haven't confirmed this but I suspect its because the syntax to set params can return mutliple results as with any regular query.
:param [{a, b, c}] => {match (n) where id(n) = 31 return 4 as a, 5 as b, n as c}
Upvotes: 0
Reputation: 67019
For some reason, the older :param
syntax is no longer documented, even though it is still supported in neo4j 4.1 (by the cypher-shell
tool and the neo4j browser). That older syntax supports the creation of parameters with map values in a very straightforward way.
For example, this will create a someObject
parameter with your desired value:
:param someObject: {data: "something", moreData: "something else"}
Upvotes: 3
Reputation: 886
Good day, What are you intent to do with that param? In general, params should be a valid JSON, so the easiest way to fix above sample is to embrace keys with double quotes and ebrace the object by single quotes: :param someObject => '{ "data": "something", "moreData": "something else" }'
Upvotes: 0