How to set a statement Label info in Cypher?

12 views
Skip to first unread message

Stephen

unread,
Oct 19, 2017, 2:55:58 AM10/19/17
to Neo4j
According to Neo4j documentation. I was running a statement cypher successfully. 
But when I tried to set a custom label to cypher, it ran into a syntax error.
public void addPerson( String name )
{
    try ( Session session = driver.session() )
    {
        session.run( "CREATE (a:$label {})", parameters( "label", name ) );
    }
}
How to solve it ?
Thanks.






Michael Hunger

unread,
Oct 19, 2017, 4:10:23 PM10/19/17
to ne...@googlegroups.com
You cannot parameterize labels, rel-types and property-keys right now.
You'll have to use string substitution, make sure to surround it with `%s` backticks  and sanitize your input.

Michael

--
You received this message because you are subscribed to the Google Groups "Neo4j" group.
To unsubscribe from this group and stop receiving emails from it, send an email to neo4j+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Michael Hunger

unread,
Oct 19, 2017, 4:11:10 PM10/19/17
to Michael Hunger, ne...@googlegroups.com
Oh and also you got it wrong, name is not a label but a property.

session.run( "CREATE (:Person {name:$name})", parameters( "name", name ) );
Reply all
Reply to author
Forward
0 new messages