Reputation: 1
This is the code I am trying to run
def get_label(tx, name):
tx.run("Match(n) where n.name=$name"
"return labels(n)",
name=name )
return "labels(n)"
with graphdb.session() as session:
Label = session.read_transaction(get_label, "usa")
I am getting this syntax error:
neo4j.exceptions.CypherSyntaxError: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input 'a': expected 'o/O' (line 1, column 36 (offset: 35)) "Match(n) where n.name=$namereturn labels(n)" ^}
Upvotes: 0
Views: 489
Reputation: 8950
First, you're missing a space or newline between $name
and return
in your query.
It should be:
"MATCH (n) WHERE n.name = $name RETURN labels(n)"
or even shorter:
"MATCH (n {name: $name}) RETURN labels(n)"
Second, you're not returning the results of tx.run
, you're returning a string. I'm not experienced in Python but the code should probably be more like:
def get_label(tx, name):
return list(tx.run("MATCH (n {name: $name}) RETURN labels(n)", name=name))
Finally, get_label
is probably a misnomer.
A node defines 0 to many labels and the implementation I suggested here would return as many lists of labels as there are matched nodes.
This might mean a single list if the name is unique among all nodes in your data set.
Upvotes: 1