cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

CypherSyntaxError: Invalid input 'H': expected 'i/I'

royinblr
Node Link

I am getting error while trying to access neo4j enterprise edition 4.0 from python api 4.0.I am using https://neo4j.com/docs/api/python-driver/4.0/ for reference.

Used below code -
<
from neo4j import GraphDatabase

uri = "neo4j://localhost:7687"
driver = GraphDatabase.driver(uri, auth=("neo4j", "pwd"))

def create_friend_of(tx, name, friend):
tx.run("CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) WHERE a.name = $name RETURN f.name AS friend", name=name, friend=friend)

with driver.session() as session:
session.write_transaction(create_friend_of, "Alice", "Bob")

driver.close()


Getting below error

CypherSyntaxError: Invalid input 'H': expected 'i/I' (line 1, column 57 (offset: 56))
"CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) WHERE a.name = $name RETURN f.name AS friend"

Please let me know the change I need to do to resolve this error.Thanks in advance.

1 ACCEPTED SOLUTION

You cannot have a WHERE after a CREATE. Not sure what you intend to do, but most likely you want to do a MATCH with a WHERE first to find a existing node and then use a simple CREATE for the relationship and the other node.

View solution in original post

3 REPLIES 3

You cannot have a WHERE after a CREATE. Not sure what you intend to do, but most likely you want to do a MATCH with a WHERE first to find a existing node and then use a simple CREATE for the relationship and the other node.

royinblr
Node Link

Thanks @stefan.armbruster .Understood the issue here. Quick example code in the below reference requires change.

https://neo4j.com/docs/api/python-driver/4.0/

Same error exists for https://neo4j.com/docs/api/python-driver/current/

def create_friend_of(tx, name, friend):
tx.run("CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) "
"WHERE a.name = $name "
"RETURN f.name AS friend", name=name, friend=friend)

should be

def create_friend_of(tx, name, friend):
tx.run("CREATE (a:Person)-[:KNOWS]->(f:Person {name: $friend}) "
, name=name, friend=friend)