Id's parametrizable? Sources for Answer "Yes" and for "No"

"label" cannot. Understood. But I struggle with id's:
According to https://neo4j.com/docs/cypher-manual/current/values-and-types/property-structural-constructed/:

Structural types cannot be used as parameters...NODE, RELATIONSHIP, and PATH are structural data types:

  • The NODE data type includes: id, label(s), and a map of properties. Note that labels are not values, but a form of pattern syntax.
  • The RELATIONSHIP data type includes: id, relationship type, a map of properties, start node id, and end node id.

But:

Parameters can be used for:

  • literals and expressions
  • node and relationship ids

and further down: valid:
MATCH (n)
WHERE elementId(n) IN $ids
RETURN n.name

It seems like you are mixing two concepts.

You cannot pass entities (nodes, relationships, or paths) as parameters when using a driver.

You cannot use parameters in queries for label values, attributes using dot notation, relationship types, nor property names in maps. The link you referenced discusses this limitation.

1 Like

Sorry, I still don't get it.
Can you elaborate please?

I can write a cypher query ...WHERE elementId(n) in $ids. (Parameters - Cypher Manual)
Makes sense to me - not only because of preventing injection.

But then I read: (https://neo4j.com/docs/cypher-manual/current/values-and-types/property-structural-constructed/:) NODES are structural data types and cannot be used as parameters. But then it says: The NODE data type includes id.

What's my error? What am I missing?

Nodes are structural data types, as are relationships and paths. These are objects specific to neo4j and they form the backbone of neo4j data and queries. A node has its own attributes. These include an elementId, a map of properties, and a list of labels. You can not pass structural data as parameters.

Your “where” clause predicate is asking if node n’s elementId (which is a string) is in a list you have passed as a query parameter. This is valid.

1 Like

Thank you! Now I've understood :slight_smile:

1 Like