Hi there,
Please kindly advise what I do wrong. I'd like to add constraints from python fuction but it doesn't work as seems Cypher gets literally "$variable" instead of variable meaning.
I get an error text:
> **CypherSyntaxError**: {code: Neo.ClientError.Statement.SyntaxError} {message: Invalid input '$': expected "FOR", "IF", "ON" or an identifier (line 1, column 19 (offset: 18))
"CREATE CONSTRAINT $cons_name IF NOT EXISTS"
^}
And here is my code:
def events_constraint(tx, cons_name, label, prop):
result = tx.run("""CREATE CONSTRAINT $cons_name IF NOT EXISTS
FOR (x:$label)
REQUIRE x.$prop IS UNIQUE
""" , cons_name = cons_name, label = label, prop = prop
)
with driver.session(database="mytest") as session:
session.execute_write(events_constraint, "TestName", "Label", "property")
So what means Invalid input '$'?? How else I can put my variable to query? Another queries are ok with this but not CREARE CONSTRAINT.