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

I am getting error while trying to access neo4j enterprise edition 4.0 from python api 4.0.I am using Neo4j Python Driver 4.2 — Neo4j Python Driver 4.2 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.

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.

1 Like

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/

1 Like

Same error exists for Neo4j Python Driver 5.3 — Neo4j Python Driver 5.3

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)