11.4. Parameters

11.4.1. Parameter for node id
11.4.2. Parameter for multiple node ids
11.4.3. Parameter for string literal
11.4.4. Parameter for index value
11.4.5. Parameter for index query
11.4.6. Numeric parameters for SKIP and LIMIT
11.4.7. Parameter for regular expression
11.4.8. Parameter setting properties on node

Cypher supports querying with parameters. This means developers don’t have to resort to string building to create a query. In addition to that, it also makes caching of execution plans much easier for Cypher.

Parameters can be used for literals and expressions in the WHERE clause, for the index value in the START clause, index queries, and finally for node/relationship ids. Parameters can not be used as for property names, relationship types and labels, since these patterns are part of the query structure that is compiled into a query plan.

Accepted names for parameter are letters and number, and any combination of these.

For details on parameters when using the Neo4j embedded Java API, see Section 5.14, “Query Parameters”. For details on using parameters via the Neo4j REST API, see Cypher queries via REST.

Below follows a comprehensive set of examples of parameter usage. The parameters are given as JSON here. Exactly how to submit them depends on the driver in use.

11.4.1. Parameter for node id

Parameters. 

{
  "id" : 0
}

Query. 

START n=node({ id })
RETURN n.name

11.4.2. Parameter for multiple node ids

Parameters. 

{
  "id" : [ 0, 1, 2 ]
}

Query. 

START n=node({ id })
RETURN n.name

11.4.3. Parameter for string literal

Parameters. 

{
  "name" : "Johan"
}

Query. 

START n=node(0,1,2)
WHERE n.name = { name }
RETURN n

11.4.4. Parameter for index value

Parameters. 

{
  "value" : "Michaela"
}

Query. 

START n=node:people(name = { value })
RETURN n

11.4.5. Parameter for index query

Parameters. 

{
  "query" : "name:Andreas"
}

Query. 

START n=node:people({ query })
RETURN n

11.4.6. Numeric parameters for SKIP and LIMIT

Parameters. 

{
  "s" : 1,
  "l" : 1
}

Query. 

START n=node(0,1,2)
RETURN n.name
SKIP { s }
LIMIT { l }

11.4.7. Parameter for regular expression

Parameters. 

{
  "regex" : ".*h.*"
}

Query. 

START n=node(0,1,2)
WHERE n.name =~ { regex }
RETURN n.name

11.4.8. Parameter setting properties on node

Parameters. 

{
  "props" : {
    "position" : "Developer",
    "name" : "Andres"
  }
}

Query. 

START n=node(0)
SET n = { props }