1

I use neo4j-rest-binding API to develop, but I face a problem when using parameters of RestCypherQueryEngine.

QueryResult<Map<String,Object>> result = engine.query("MATCH (n:{label}) RETURN n", MapUtil.map("label", label));

label is the parameter I assign in the map structure, but it has an error:

org.neo4j.rest.graphdb.RestResultException: Invalid input '{': expected whitespace or an identifier (line 1, column 10)
"MATCH (n:{label}) RETURN n"
          ^ at
SyntaxException
   org.neo4j.cypher.internal.compiler.v2_0.parser.CypherParser$$anonfun$parse$1.apply(CypherParser.scala:51)
   org.neo4j.cypher.internal.compiler.v2_0.parser.CypherParser$$anonfun$parse$1.apply(CypherParser.scala:41)
...

I can use another method to solve this problem:

QueryResult<Map<String,Object>> result = engine.query("MATCH (n:" + label +") RETURN n", null);

But I think the above method is not appropriate when I want to pass multiple parameters.

1 Answer 1

1

:{ is a syntactical error. As the exception tells you, Cypher expects an identifier after a colon - namely, the name of a label - and an identifier (as in most languages) cannot contain a bracket.

It sounds like you're confused about the difference between labels and parameters:

The following would be valid: MATCH (n:employee{name:"foo"}) Here, employee is a label. You can apply an arbitrary number of labels delimited by colons. {name:"foo"} is a parameter block - note that it contains both the field you want to match and the value. So, this query will return all nodes labelled employee with a name value of "foo". MATCH (n:employee:custodian{name:"foo"}) will give you all employees who are custodians named "foo".

If you want all nodes with a name value of "foo", use MATCH (n {name:"foo"}) (note the absence of a colon).

Edit (responding to your comment) There are two differences between your query and the one in the example you're referring to, start n=node({id}) return n is, obviously, a START clause, which do very different things and have different syntactical rules from MATCH clauses: The id in ({id)} is simply a value to look up in an index. In a MATCH clause, what goes inside a { } block are key-value pairs, as is explained above. Inside a parameter block (i.e. a set of braces), colons are used to separate keys from values. A colon outside the brackets in a MATCH clause are used to separate labels which are different different things entirely.

The second difference is that, if you look more closely at the START clause, there is a parenthesis separating the colon from the bracket. :{ is never okay, which is what your error message is telling you.

Sign up to request clarification or add additional context in comments.

3 Comments

Thank you for your reply. I understand the difference between label and properties. But the {label} is the parameter I assigned, it might be Employee or Boss. It likes the printf in C++, such as printf ("Characters: %c %c \n", 'a', 65);. The example of neo4j-rest-binding is in https://github.com/neo4j/java-rest-binding/wiki/Connect-and-Query-Example.
Many thanks! Do you have any idea if I want to pass parameters to labels? This is my main question.
@LoveTW "Pass parameters to labels" does not make sense. Tell me what you're trying to do, what you want this query to return, and I'll help you understand how labels and/or parameters might fit in

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.