10.8. Call

The CALL clause is used to call a procedure deployed in the database.

The examples showing how to use arguments when invoking procedures all use the following procedure:

public class IndexingProcedure
{
    @Context
    public GraphDatabaseService db;

    /**
     * Adds a node to a named legacy index. Useful to, for instance, update
     * a full-text index through cypher.
     * @param indexName the name of the index in question
     * @param nodeId id of the node to add to the index
     * @param propKey property to index (value is read from the node)
     */
    @Procedure
    @PerformsWrites
    public void addNodeToIndex( @Name("indexName") String indexName,
                                @Name("node") long nodeId,
                                @Name("propKey" ) String propKey )
    {
        Node node = db.getNodeById( nodeId );
        db.index()
          .forNodes( indexName )
          .add( node, propKey, node.getProperty( propKey ) );
    }
}
[Note]Note

This clause cannot be combined with other clauses.

Call a procedure

This invokes the built-in procedure db.labels, which lists all in-use labels in the database.

Query 

CALL db.labels

Result

label
2 rows

"User"

"Administrator"

Try this query live create (_0:`User`:`Administrator` {`name`:"Adrian"}) ; CALL db.labels

Call a procedure with literal arguments

This invokes the example procedure org.neo4j.procedure.example.addNodeToIndex using arguments that are written out directly in the statement text. This is called literal arguments.

Query 

CALL org.neo4j.procedure.example.addNodeToIndex('users', 0, 'name')

Since our example procedure does not return any result, the result is empty.

Result

(empty result)

Try this query live create (_0:`User`:`Administrator` {`name`:"Adrian"}) ; CALL org.neo4j.procedure.example.addNodeToIndex('users', 0, 'name')

Call a procedure with parameter arguments

This invokes the example procedure org.neo4j.procedure.example.addNodeToIndex using parameters. The procedure arguments are satisfied by matching the parameter keys to the named procedure arguments.

Parameters 

{
  "indexName" : "users",
  "node" : 0,
  "propKey" : "name"
}

Query 

CALL org.neo4j.procedure.example.addNodeToIndex

Since our example procedure does not return any result, the result is empty.

Result

(empty result)

Call a procedure with mixed literal and parameter arguments

This invokes the example procedure org.neo4j.procedure.example.addNodeToIndex using both literal and parameterized arguments.

Parameters 

{
  "node" : 0
}

Query 

CALL org.neo4j.procedure.example.addNodeToIndex('users', { node }, 'name')

Since our example procedure does not return any result, the result is empty.

Result

(empty result)

Call a procedure within a complex query

This invokes the built-in procedure db.labels to count all in-use labels in the database

Query 

CALL db.labels()YIELD label
RETURN count(label) AS numLabels

Since the procedure call is part of a larger query, all outputs must be named explicitly

Result

numLabels
1 row

2

Try this query live create (_0:`User`:`Administrator` {`name`:"Adrian"}) ; CALL db.labels() YIELD label RETURN count(label) AS numLabels

Call a procedure within a complex query and rename its outputs

This invokes the built-in procedure db.propertyKeys as part of counting the number of nodes per property key in-use in the database

Query 

CALL db.propertyKeys()YIELD propertyKey AS prop
MATCH (n)
WHERE n[prop] IS NOT NULL RETURN prop, count(n) AS numNodes

Since the procedure call is part of a larger query, all outputs must be named explicitly

Result

propnumNodes
1 row

"name"

1

Try this query live create (_0:`User`:`Administrator` {`name`:"Adrian"}) ; CALL db.propertyKeys() YIELD propertyKey AS prop MATCH (n) WHERE n[prop] IS NOT NULL RETURN prop, count(n) AS numNodes