Clauses

This section contains information on all the clauses in the Cypher® query language.

Reading clauses

These comprise clauses that read data from the database.

The flow of data within a Cypher query is an unordered sequence of maps with key-value pairs — a set of possible bindings between the variables in the query and values derived from the database. This set is refined and augmented by subsequent parts of the query.

Clause Description

MATCH

Specify the patterns to search for in the database.

OPTIONAL MATCH

Specify the patterns to search for in the database while using nulls for missing parts of the pattern.

Projecting clauses

These comprise clauses that define which expressions to return in the result set. The returned expressions may all be aliased using AS.

Clause Description

RETURN …​ [AS]

Defines what to include in the query result set.

WITH …​ [AS]

Allows query parts to be chained together, piping the results from one to be used as starting points or criteria in the next.

UNWIND …​ [AS]

Expands a list into a sequence of rows.

FINISH

Defines a query to have no result.

Reading sub-clauses

These comprise sub-clauses that must operate as part of reading clauses.

Sub-clause Description

WHERE

Adds constraints to the patterns in a MATCH or OPTIONAL MATCH clause or filters the results of a WITH clause.

ORDER BY [ASC[ENDING] | DESC[ENDING]]

A sub-clause following RETURN or WITH, specifying that the output should be sorted in either ascending (the default) or descending order. As of Neo4j 5.24, it can also be used as a standalone clause.

SKIP / OFFSET

Defines from which row to start including the rows in the output. As of Neo4j 5.24, it can be used as a standalone clause.

LIMIT

Constrains the number of rows in the output. As of Neo4j 5.24, it can be used as a standalone clause.

Writing clauses

These comprise clauses that write the data to the database.

Clause Description

CREATE

Create nodes and relationships.

DELETE

Delete nodes, relationships or paths. Any node to be deleted must also have all associated relationships explicitly deleted.

DETACH DELETE

Delete a node or set of nodes. All associated relationships will automatically be deleted.

SET

Update labels on nodes and properties on nodes and relationships.

REMOVE

Remove properties and labels from nodes and relationships.

FOREACH

Update data within a list, whether components of a path, or the result of aggregation.

Reading/Writing clauses

These comprise clauses that both read data from and write data to the database.

Clause Description

MERGE

Ensures that a pattern exists in the graph. Either the pattern already exists, or it needs to be created.

--- ON CREATE

Used in conjunction with MERGE, this write sub-clause specifies the actions to take if the pattern needs to be created.

--- ON MATCH

Used in conjunction with MERGE, this write sub-clause specifies the actions to take if the pattern already exists.

CALL …​ [YIELD …​ ]

Invokes a procedure deployed in the database and return any results.

Subquery clauses

Clause Description

CALL { …​ }

Evaluates a subquery, typically used for post-union processing or aggregations.

CALL { …​ } IN TRANSACTIONS

Evaluates a subquery in separate transactions. Typically used when modifying or importing large amounts of data.

Set operations

Clause Description

UNION

Combines the result of multiple queries into a single result set. Duplicates are removed.

UNION ALL

Combines the result of multiple queries into a single result set. Duplicates are retained.

Multiple graphs

Clause Description

USE

Determines which graph a query, or query part, is executed against. Fabric

Importing data

Clause Description

LOAD CSV

Use when importing data from CSV files.

CALL { …​ } IN TRANSACTIONS

This clause may be used to prevent an out-of-memory error from occurring when importing large amounts of data using LOAD CSV.

Listing functions and procedures

Clause Description

SHOW FUNCTIONS

List the available functions.

SHOW PROCEDURES

List the available procedures.

Configuration Commands

Clause Description

SHOW SETTINGS

List configuration settings.

Transaction Commands

Clause Description

SHOW TRANSACTIONS

List the available transactions.

TERMINATE TRANSACTIONS

Terminate transactions by their IDs.

Reading hints

These comprise clauses used to specify planner hints when tuning a query. More details regarding the usage of these — and query tuning in general — can be found in Planner hints and the USING keyword.

Hint Description

USING INDEX

Index hints are used to specify which index, if any, the planner should use as a starting point.

USING INDEX SEEK

Index seek hint instructs the planner to use an index seek for this clause.

USING SCAN

Scan hints are used to force the planner to do a label scan (followed by a filtering operation) instead of using an index.

USING JOIN

Join hints are used to enforce a join operation at specified points.

Index and constraint clauses

These comprise clauses to create, show, and drop indexes and constraints.

Clause Description

CREATE | SHOW | DROP INDEX

Create, show or drop an index.

CREATE | SHOW | DROP CONSTRAINT

Create, show or drop a constraint.

Administration clauses

Cypher includes commands to manage databases, aliases, servers, and role-based access control. To learn more about each of these, see: