Skip to content

Select Cypher version #1123

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 29 commits into
base: cypher-25
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
8514b29
write cypher selection page
JPryce-Aklundh Nov 14, 2024
85f4663
change 2025.01 to 2025.02
JPryce-Aklundh Dec 20, 2024
8b25fa4
change page-version to current in links
JPryce-Aklundh Jan 10, 2025
6a54b9a
2025.03 update and procedures section
JPryce-Aklundh Feb 3, 2025
e1a6900
Merge branch 'cypher-25' into select_version
JPryce-Aklundh Feb 25, 2025
b5b82b4
add config info
JPryce-Aklundh Feb 25, 2025
11e8788
conflict fix
JPryce-Aklundh Feb 25, 2025
5e285b4
Merge branch 'select_version' of https://github.com/JPryce-Aklundh/do…
JPryce-Aklundh Feb 25, 2025
fc023a6
fix links
JPryce-Aklundh Feb 25, 2025
360f226
clarify table
JPryce-Aklundh Feb 25, 2025
3d5f74f
typo in example
stefano-ottolenghi Feb 25, 2025
5b0baa8
ambiguity clearup
JPryce-Aklundh Feb 25, 2025
1b3f808
Merge branch 'select_version' of https://github.com/JPryce-Aklundh/do…
JPryce-Aklundh Feb 25, 2025
7be498c
typos
stefano-ottolenghi Feb 25, 2025
8d44f62
post review edit
JPryce-Aklundh Feb 25, 2025
4b4133b
Merge branch 'select_version' of https://github.com/JPryce-Aklundh/do…
JPryce-Aklundh Feb 25, 2025
034101b
correction
JPryce-Aklundh Feb 26, 2025
b8a9d64
add links to ops manual privilege and update default value
JPryce-Aklundh Feb 26, 2025
66afae4
2025.03 to 2025.04
JPryce-Aklundh Mar 12, 2025
b4f0831
note attempt
JPryce-Aklundh Mar 12, 2025
2bf10cc
conflict fix
JPryce-Aklundh Mar 12, 2025
0dfb4b9
2025.05 update
JPryce-Aklundh Apr 3, 2025
6dc83e8
Merge branch 'cypher-25' into select_version
JPryce-Aklundh Apr 3, 2025
1c72599
merge cypher-25 branch
JPryce-Aklundh Apr 17, 2025
9b847b0
draft update of default language information
JPryce-Aklundh Apr 17, 2025
096d0d3
Merge branch 'select_version' of https://github.com/JPryce-Aklundh/do…
JPryce-Aklundh Apr 17, 2025
40e019d
update
JPryce-Aklundh Apr 17, 2025
11b09df
remove inexplicable underscores
JPryce-Aklundh Apr 17, 2025
4e1bf7d
config setting underscores
JPryce-Aklundh Apr 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions modules/ROOT/content-nav.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* xref:queries/index.adoc[]
** xref:queries/concepts.adoc[]
** xref:queries/basic.adoc[]
** xref:queries/select-version.adoc[]
** xref:queries/composed-queries/index.adoc[]
*** xref:queries/composed-queries/combined-queries.adoc[]
*** xref:queries/composed-queries/conditional-queries.adoc[]
Expand Down
1 change: 1 addition & 0 deletions modules/ROOT/pages/queries/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ It also discusses how to compose combined queries using `UNION` and conditional

* xref:queries/concepts.adoc[]
* xref:queries/basic.adoc[]
* xref:queries/select-version.adoc[]
* xref:queries/composed-queries/index.adoc[]
** xref:queries/composed-queries/combined-queries.adoc[]
** xref:queries/composed-queries/conditional-queries.adoc[] label:new[Introduced in Neo4j 2025.06]
Expand Down
252 changes: 252 additions & 0 deletions modules/ROOT/pages/queries/select-version.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,252 @@
:description: Information about how to select Cypher version for queries or databases.

= Select Cypher version

Users can specify the version of Cypher in which they want to run their queries, choosing between Cypher 5 and Cypher 25.
The Cypher version can be set for individual queries or as the default language for a database.

[[cypher-versions-explained]]
== Cypher 5, Cypher 25, and Neo4j explained

Starting in 2025, the Neo4j server transitioned to a calendar-based versioning system.
This means Neo4j will no longer use its previous semantic versioning and release pattern (e.g., 5.25, 5.26).
Instead, releases from 2025 onwards will follow a *YYYY.MM* format, beginning with version 2025.01 released in January 2025, followed by 2025.02 released in February 2025, and so on.

Cypher 25 is introduced alongside Neo4j 2025.06.
However, users running Neo4j version 2025.06 or later can choose to run their queries using the previous version of Cypher: Cypher 5.
If so, Neo4j will use Cypher as it existed at the time of the Neo4j **TBC** release.

[IMPORTANT]
All new databases created after the release of 2025.06 will continue to use Cypher 5 as their default language.
To change the default language, see xref:queries/select-version.adoc#alter-default-cypher-version[Alter the default Cypher version for a database].
See also xref:queries/select-version.adoc#config-database-upgrades[Cypher versions, configuration settings, and DBMS upgrades] for information about what default Cypher version is used when upgrading a DBMS.

For information about updates to Cypher in different Neo4j versions, see xref:deprecations-additions-removals-compatibility.adoc[].
For information about Cypher 5, see the link:https://neo4j.com/docs/cypher-manual/5/introduction/[Cypher 5 Manual].

[[selection-query-cypher-version]]
== Select the Cypher version for queries

To select the Cypher version of a query, prepend it with `CYPHER <language version>`.

Selecting `CYPHER 5` ensures that the query will be executed using the language as it existed at the time of the Neo4j **TBC** release.
Any changes introduced after the **TBC** release will not affect the query.

Selecting `CYPHER 25` ensures that the query will be executed using the language as it exists in the version of Neo4j that the database is currently running, provided it is on Neo4j 2025.06 or later.

Below are two examples showing the two versions of Cypher behaving differently.

.Differences in setting properties between Cypher 5 and Cypher 25
======
The first query uses a `RELATIONSHIP` instead of `MAP` on the right-hand side of a xref:clauses/set.adoc[`SET`] clause.
This was allowed in Cypher 5, but disallowed in Cypher 25, which requires that the xref:functions/scalar.adoc#functions-properties[`properties()`] function is used to get the map of properties from nodes or relationships before referencing them in a `SET` clause.

.Setting properties on a node from a relationship using Cypher 5
[source, cypher]
----
CYPHER 5
MATCH (n:Order)-[r:SHIPPED_TO]->(:Address)
SET n = r
----

.Setting properties on a node from a relationship using Cypher 25
[source, cypher]
----
CYPHER 25
MATCH (n:Order)-[r:SHIPPED_TO]->(:Address)
SET n = properties(r)
----
======

.Differences in listing constraints between Cypher 5 and Cypher 25
======
In this example, the same statement listing the `name` and `type` of the xref:constraints/index.adoc[constraints] in a database is executed first using Cypher 5 and then with Cypher 25.
Note that the return values in the `type` column have been updated in the results from the statement run with Cypher 25.

////
CREATE CONSTRAINT node_uniqueness_constraint
FOR (n:Label) REQUIRE n.property IS UNIQUE;
CREATE CONSTRAINT rel_uniqueness_constraint
FOR ()-[r:REL_TYPE]-() REQUIRE r.property IS UNIQUE;
////

.Listing the constraint name and type values using Cypher 5
[source, cypher]
----
CYPHER 5
SHOW CONSTRAINTS YIELD name, type
----

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| name | type

| "node_uniqueness_constraint" | "UNIQUENESS"
| "rel_uniqueness_constraint" | "RELATIONSHIP_UNIQUENESS"

2+d|Rows: 2
|===

.Listing the constraint name and type values using Cypher 25
[source, cypher]
----
CYPHER 25
SHOW CONSTRAINTS YIELD name, type
----

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| name | type

| "node_uniqueness_constraint" | "NODE_PROPERTY_UNIQUENESS"
| "rel_uniqueness_constraint" | "RELATIONSHIP_PROPERTY_UNIQUENESS"

2+d|Rows: 2
|===

======

If a database has specified a default Cypher version, it is possible to set a different Cypher version for individual queries.
For example, if a database is created with Cypher 5 as its default language, prepending a query run on that database with `CYPHER 25` ensures the query uses Cypher 25.

[[procedures-and-functions]]
=== Procedures and functions

link:{neo4j-docs-base-uri}/operations-manual/current/procedures[Procedures] and xref:functions/index.adoc[functions] (including built-in and link:{neo4j-docs-base-uri}/apoc/current/[APOC]) are tied to a specific Cypher language version.
Therefore, procedures and functions in Neo4j 2025.06+ and APOC 2025.06+ (both of which have Cypher 5 as their default language) may behave differently depending on what version of Cypher is used.

For example, APOC 2025.06 removed Cypher 25 support of the procedure `apoc.create.uuids()`, meaning it is not available to queries running Cypher 25.
However, it can still be used on APOC 2025.06 if queries are prepended with `CYPHER 5`, or if the database’s default version is set to `CYPHER 5`.
In this case, Neo4j will use APOC and Cypher as they existed at the time of the **TBC** release.

.Using a procedure removed in Cypher 25 with APOC 2025.06+
[source, cypher]
----
CYPHER 5
CALL apoc.create.uuids(10)
----

[[cypher-selection-with-other-query-options]]
=== Combine Cypher version selection with other query options

It is possible to combine Cypher version selection with other xref:planning-and-tuning/query-tuning.adoc[query options].
The below example selects both the version and the xref:planning-and-tuning/runtimes/concepts.adoc[runtime] of Cypher for the same query:

.Combining Cypher version selection with other query options
[source, cypher]
----
CYPHER 5 runtime=parallel
MATCH (n:Person)
RETURN n.name
----

[[select-default-cypher-version]]
== Select the default Cypher version when creating a database

Databases created on Neo4j 2025.06 or later will continue to have Cypher 5 as their default language (if {neo4j-docs-base-uri}/operations-manual/current/configuration/configuration-settings/#config_db.query.default_language[`config_db.query.default_language`] is set to `CYPHER_5` -- see xref:queries/select-version.adoc#config-database-upgrades[Cypher versions, configuration settings, and DBMS upgrades] below).
This is true for link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/#manage-database-systems[system, standard, and composite] Neo4j databases.

To select a different default Cypher version for a database, add `DEFAULT LANGUAGE <language version>` to the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/standard-databases/create-databases/[`CREATE DATABASE`] statement.
This can be done on any Neo4j database.

Selecting `CYPHER 5` as the default database language ensures that every query run on that database uses the language as it existed at the time of the Neo4j **TBC** release (unless a query is prepended with `CYPHER 25`, which overrides this default).
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this bit seems more odd when considering CYPHER 5 is the default, it feels more like it's pointing out a difference to the default (probably due to being added to do just that before :P)

Any changes introduced after the **TBC** release will not affect the semantics of the query.

.Create a database with Cypher 5 as the default language
[source, cypher]
----
CREATE DATABASE my_database DEFAULT LANGUAGE CYPHER 5
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have linked back to these sections from the operations manual documentation of these commands. There doesn't seem much point documenting it twice.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think all sections related to database administration should go to the Operations manual, and here, we can add just one link.

----

Selecting `CYPHER 25` ensures that the query will be executed using the language as it exists in the version of Neo4j that the database is currently running, provided it is on Neo4j 2025.06 or later (unless a query is prepended with `CYPHER 5`, which overrides this default).

.Create a database with Cypher 25 as the default language
[source, cypher]
----
CREATE DATABASE my_new_database DEFAULT LANGUAGE CYPHER 25
----

[[alter-default-cypher-version]]
== Alter the default Cypher version for a database

To alter the default Cypher version on a database, add `SET DEFAULT LANGUAGE <language version>` to the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/standard-databases/alter-databases/[`ALTER DATABASE`] command.

[NOTE]
Selecting a default Cypher version on a database requires the link:{neo4j-docs-base-uri}/operations-manual/current/authentication-authorization/dbms-administration/#access-control-dbms-administration-database-management[`SET DATABASE DEFAULT LANGUAGE`] privilege.

.Set Cypher 5 as the default language on an existing database
[source, cypher]
----
ALTER DATABASE my_new_database SET DEFAULT LANGUAGE CYPHER 5
----

.Set Cypher 25 as the default language on an existing database
[source, cypher]
----
ALTER DATABASE my_database SET DEFAULT LANGUAGE CYPHER 25
----

[[show-cypher-versions]]
== Show the Cypher version of databases

The Cypher version of a database can be seen using the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/standard-databases/listing-databases/[`SHOW DATABASES`] command as follows:

.Retrieve the default language on existing databases
[source, cypher]
----
SHOW DATABASES YIELD name, defaultLanguage
----

[NOTE]
`defaultLanguage` is not returned by default.
It can only be returned with `YIELD`.
For more information, see the link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/standard-databases/listing-databases/#_show_databases_output[Operations Manual -> `SHOW DATABASES` output].

.Result
[role="queryresult",options="header,footer",cols="2*<m"]
|===
| name | defaultLanguage

| "my_database" | "CYPHER 25"
| "my_new_database" | "CYPHER 5"
| "system" | "CYPHER 25"

2+d|Rows: 3
|===

[[config-database-upgrades]]
== Cypher versions, configuration settings, and DBMS upgrades

Changing the Cypher version of new databases in a DBMS can also be done with the setting link:{neo4j-docs-base-uri}/operations-manual/current/configuration/configuration-settings/#config_db.query.default_language[`config_db.query.default_language`] (default value: `CYPHER_5`).
This setting determines the default language for new databases where it has not been specified as part of a `CREATE` or `ALTER` database command.
For example, `config_db.query.default_language=CYPHER_25` will set Cypher 25 as the default language for a DBMS.
For more information about using configuration settings, see the link:{neo4j-docs-base-uri}/operations-manual/current/configuration/[Operations Manual -> Configuration].

The table below outlines which Cypher version is assigned to databases in different upgrade or installation scenarios:

[cols="3", options="header"]
|===
| Scenario | `db.query.default_language` | Databases

| *Standard DBMS upgrade to Neo4j 2025.06+*
| Unset
| *Existing system database:* `CYPHER 5` +
*Existing user databases:* `CYPHER 5` +
*New user databases default:* `CYPHER 5`
Comment on lines +236 to +237
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to add something like this for the remote alias case I mentioned on slack (in addition to having a short sentence about it somewhere as we discussed)

Suggested change
*Existing user databases:* `CYPHER 5` +
*New user databases default:* `CYPHER 5`
*Existing user databases:* `CYPHER 5` +
*Existing non-constituent remote database aliases:* `CYPHER 5` +
*New user databases and non-constituent remote database aliases default:* `CYPHER 5`

(if yes, then we should also update the other two rows in the table)


| *Custom DBMS upgrade to Neo4j 2025.06+*
| Manually set to `CYPHER_25` by administrator
| *Existing system database:* `CYPHER 5` +
*Existing user databases:* `CYPHER 5` +
*New user databases default:* `CYPHER 25`

| *New installation of Neo4j 2025.06+*
| Set to `CYPHER_5`
| *New system database:* `CYPHER 5` +
*New user databases default:* `CYPHER 5`

|===

For more information about upgrading and migrating Neo4j databases, see the link:{neo4j-docs-base-uri}/upgrade-migration-guide/current/[Upgrade and migration guide].