You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Naming database aliases in composite databases follows the same rule as xref:database-administration/aliases/naming-aliases.adoc[naming aliases for standard databases].
226
226
However, when it comes to escaping names using backticks, there are some additional things to consider:
227
227
228
-
=== Quoting database alias and composite database names
228
+
Dots in alias names are ambiguous.
229
+
They could either be interpreted as part of the name itself, or as the dot that separates a composite namespace from the alias name.
230
+
231
+
[role=label--new-2025.06]
232
+
=== Conflicting names
233
+
In versions earlier than Neo4j 2025.06, it is possible to create conflicting aliases, such as the constituent alias `flowers` within the composite database `garden` as well as the non-composite local alias `garden.flowers`.
234
+
Both of these are referred to by the same name, `garden.flowers`.
235
+
236
+
Neo4j 2025.06 and later versions ensure that no such conflicts exist and throw an exception when attempting to create a new alias with the same name as an existing alias.
237
+
238
+
[.tabbed-example]
239
+
=====
240
+
[role=include-with-cypher-5]
241
+
======
242
+
Creating a regular alias with the same name as an existing composite constituent is disallowed:
243
+
244
+
.Query
245
+
[source, cypher]
246
+
----
247
+
CYPHER 5 CREATE COMPOSITE DATABASE `garden`
248
+
CYPHER 5 CREATE ALIAS `garden`.`flowers` FOR DATABASE `northwind-graph`
249
+
CYPHER 5 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
250
+
----
251
+
252
+
.Error message
253
+
[source, output, role="noheader"]
254
+
----
255
+
Failed to create the specified database alias 'garden.flowers': Database name or alias already exists.
256
+
----
257
+
The exception has the GQLSTATUS code link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42001[42001 - invalid syntax] with the cause link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42N11[42N11 - graph reference already exists].
258
+
259
+
======
260
+
261
+
[role=include-with-cypher-25]
262
+
======
263
+
264
+
Creating a regular alias with the same name as an existing composite constituent is disallowed.
265
+
In Cypher 25, the two names are considered the same since the parts are not quoted separately as they would be in Cypher 5.
266
+
267
+
.Query
268
+
[source, cypher]
269
+
----
270
+
CYPHER 25 CREATE COMPOSITE DATABASE `garden`
271
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
272
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
273
+
----
274
+
275
+
.Error message
276
+
[source, output, role="noheader"]
277
+
----
278
+
Failed to create the specified database alias 'garden.flowers': Database name or alias already exists.
279
+
----
280
+
The exception has the GQLSTATUS code link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42001[42001 - invalid syntax] with the cause link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42N11[42N11 - graph reference already exists].
281
+
======
282
+
=====
283
+
284
+
[.tabbed-example]
285
+
=====
286
+
[role=include-with-cypher-5]
287
+
======
288
+
Creating a composite constituent with the same name as an existing non-composite alias is disallowed.
289
+
This example scenario is already prevented on the second line; thus, the constituent on the third line cannot be created.
290
+
291
+
.Query
292
+
[source, cypher]
293
+
----
294
+
CYPHER 5 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
295
+
CYPHER 5 CREATE COMPOSITE DATABASE `garden`
296
+
CYPHER 5 CREATE ALIAS `garden`.`flowers` FOR DATABASE `northwind-graph`
297
+
----
298
+
299
+
.Error message
300
+
[source, output, role="noheader"]
301
+
----
302
+
Cannot create database 'garden' because another database 'garden.flowers' exists with an ambiguous name.
303
+
----
304
+
The exception has the GQLSTATUS code link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42N87[42N87 - database or alias with similar name exists].
305
+
======
306
+
307
+
[role=include-with-cypher-25]
308
+
======
309
+
310
+
Creating a composite constituent with the same name as an existing non-composite alias is disallowed.
311
+
This example scenario is already prevented on the second line; thus, the constituent on the third line cannot be created.
312
+
The Cypher 25 syntax makes no distinction between the names to clarify that they are considered equivalent.
313
+
314
+
.Query
315
+
[source, cypher]
316
+
----
317
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
318
+
CYPHER 25 CREATE COMPOSITE DATABASE `garden`
319
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
320
+
----
321
+
322
+
.Error message
323
+
[source, output, role="noheader"]
324
+
----
325
+
Cannot create database 'garden' because another database 'garden.flowers' exists with an ambiguous name.
326
+
----
327
+
The exception has GQLSTATUS code link:{neo4j-docs-base-uri}/status-codes/current/errors/gql-errors/42N87[42N87 - database or alias with similar name exists].
328
+
======
329
+
=====
330
+
331
+
332
+
333
+
[role=label--new-2025.06]
334
+
=== Cypher 25 specific behaviour
335
+
==== Accessing an existing alias with dots
336
+
337
+
Cypher 25 relies on the guarantee that no conflicting names are allowed in Neo4j 2025.06 and later.
338
+
The following queries all act on the same alias, regardless of whether that alias is a composite constituent or not.
339
+
The special quoting of separate name parts that is necessary in Cypher 5 is not permitted in Cypher 25.
340
+
341
+
.Parameters
342
+
[source, javascript]
343
+
----
344
+
{
345
+
"name": "my.garden.beautiful.flowers"
346
+
}
347
+
----
348
+
.Query
349
+
[source, cypher]
350
+
----
351
+
CYPHER 25 ALTER ALIAS `my.garden.beautiful.flowers` SET DATABASE PROPERTIES { perennial: true }
352
+
CYPHER 25 ALTER ALIAS $name SET DATABASE PROPERTIES { perennial: true }
353
+
CYPHER 25 USE `my.garden.beautiful.flowers` RETURN 1
354
+
----
355
+
356
+
==== Creating a new alias with dots
357
+
358
+
During `CREATE`, Cypher 25 splits the given name on each dot, left to right, and checks if a corresponding composite database exists.
359
+
If no composite database is found, Cypher 25 falls back to creating a regular non-composite alias.
360
+
361
+
For example:
362
+
363
+
.Query
364
+
[source, cypher]
365
+
----
366
+
CYPHER 25 CREATE COMPOSITE DATABASE `my.garden`
367
+
CYPHER 25 CREATE ALIAS `my.garden.beautiful.flowers` FOR DATABASE `northwind-graph`
368
+
----
369
+
370
+
The query attempts to create the following aliases in the given order:
371
+
372
+
. Constituent alias `garden.beautiful.flowers` within composite database `my`.
373
+
. Constituent alias `beautiful.flowers` within composite database `my.garden`.
374
+
. Constituent alias `flowers` within composite database `my.garden.beautiful`.
375
+
. Regular non-composite alias `my.garden.beautiful.flowers`.
376
+
377
+
When it finds the composite database `my.garden`, it creates the constituent alias `beautiful.flowers` within that composite.
378
+
379
+
380
+
381
+
=== Cypher 5 specific behaviour
382
+
383
+
==== Quoting database alias and composite database names
229
384
230
385
The composite database name and the database alias name need to be quoted individually.
231
386
Backticks may be added regardless of whether the name contains special characters or not, so it is good practice to always backtick both names, e.g. `++`composite`++.++`alias`++`.
387
+
[NOTE]
388
+
====
389
+
Separating composite database name and alias name with backticks is no longer supported in Cypher 25.
390
+
See <<_cypher_25_specific_behaviour, Cypher 25 specific behaviour>> for details.
391
+
====
232
392
233
393
The following example creates a database alias named `my alias with spaces` as a constituent in the composite database named `my-composite-database-with-dashes`:
CREATE ALIAS `my-composite-database-with-dashes`.`my alias with spaces` FOR DATABASE `northwind-graph`
405
+
CYPHER 5 CREATE ALIAS `my-composite-database-with-dashes`.`my alias with spaces` FOR DATABASE `northwind-graph`
246
406
----
247
407
248
408
When not quoted individually, a database alias with the full name `my alias with.dots and spaces` gets created instead:
249
409
250
410
.Query
251
411
[source, cypher]
252
412
----
253
-
CREATE ALIAS `my alias with.dots and spaces` FOR DATABASE `northwind-graph`
413
+
CYPHER 5 CREATE ALIAS `my alias with.dots and spaces` FOR DATABASE `northwind-graph`
254
414
----
255
415
256
-
=== Handling multiple dots
416
+
==== Handling multiple dots
257
417
258
418
//Examples where dots are not separators between composite name and alias name are impossible to test, because the right escaping cannot be inferred automatically.
259
419
@@ -263,18 +423,20 @@ Though these always need to be quoted in order to avoid ambiguity with the compo
263
423
.Query
264
424
[source, cypher, role=test-skip]
265
425
----
266
-
CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
426
+
CYPHER 5 CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
267
427
----
268
428
269
429
.Query
270
430
[source, cypher, role=test-skip]
271
431
----
272
-
CREATE ALIAS `my.composite.database.with.dots`.`my.other.alias.with.dots` FOR DATABASE `northwind-graph`
432
+
CYPHER 5 CREATE ALIAS `my.composite.database.with.dots`.`my.other.alias.with.dots` FOR DATABASE `northwind-graph`
273
433
----
274
434
275
-
276
-
[role=label--deprecated]
277
-
=== Single dots and local database aliases
435
+
==== Single dots and local database aliases
436
+
[NOTE]
437
+
====
438
+
As of Neo4j 2025.06, this feature is no longer deprecated.
439
+
====
278
440
279
441
There is a special case for local database aliases with a single dot without any existing composite database.
280
442
If a composite database `some` exists, the query below will create a database alias named `alias` within the composite database `some`.
@@ -283,10 +445,10 @@ If no such database exists, however, the same query will instead create a databa
283
445
.Query
284
446
[source, cypher]
285
447
----
286
-
CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
448
+
CYPHER 5 CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
287
449
----
288
450
289
-
=== Handling parameters
451
+
==== Handling parameters
290
452
291
453
When using parameters, names cannot be quoted.
292
454
When the given parameter includes dots, the first dot will be considered the divider for the composite database.
@@ -304,7 +466,7 @@ Consider the query with parameter:
304
466
.Query
305
467
[source, cypher]
306
468
----
307
-
CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
469
+
CYPHER 5 CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
308
470
----
309
471
310
472
If the composite database `mysimplecompositedatabase` exists, then a database alias `myalias` will be created in that composite database.
@@ -326,7 +488,7 @@ If `mycompositedatabase` does not exist, the command will create a database alia
326
488
327
489
In these cases, it is recommended to avoid parameters and explicitly quote the composite database name and alias name separately to avoid ambiguity.
328
490
329
-
=== Handling parameters
491
+
==== Handling parameters
330
492
331
493
Further special handling with parameters is needed for database aliases and similarly named composite databases.
332
494
@@ -335,8 +497,8 @@ Consider the setup:
335
497
.Query
336
498
[source, cypher, role="noheader test-skip"]
337
499
----
338
-
CREATE COMPOSITE DATABASE foo
339
-
CREATE ALIAS `foo.bar` FOR DATABASE `northwind-graph`
500
+
CYPHER 5 CREATE COMPOSITE DATABASE foo
501
+
CYPHER 5 CREATE ALIAS `foo.bar` FOR DATABASE `northwind-graph`
340
502
----
341
503
342
504
The alias `foo.bar` does not belong to the composite database `foo`.
@@ -354,7 +516,7 @@ Dropping this alias using parameters fails with an error about a missing alias:
Copy file name to clipboardExpand all lines: modules/ROOT/pages/database-administration/aliases/naming-aliases.adoc
+3-2Lines changed: 3 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,15 +10,16 @@ The following naming rules apply:
10
10
* A name is a valid identifier.
11
11
* Name length can be up to 65534 characters.
12
12
* Names cannot end with dots.
13
-
* Unquoted dots signify that the database alias belongs to a composite database, separating the composite database name and the alias name.
14
13
* Names that begin with an underscore or with the prefix `system` are reserved for internal use.
15
14
* Non-alphabetic characters, including numbers, symbols, dots, and whitespace characters, can be used in names, but must be quoted using backticks.
15
+
* Dots (`.`) are interpreted as a delimiter between a composite database and a constituent alias name if a matching composite database exists.
16
+
Otherwise, Neo4j interprets the dot as simply part of the database name.
16
17
17
18
The name restrictions and escaping rules apply to all the different database alias commands.
18
19
19
20
[NOTE]
20
21
====
21
22
Having dots (`.`) in the database alias names is not recommended.
22
23
This is due to the difficulty of determining if a dot is part of the database alias name or a delimiter for a database alias in a composite database.
23
-
For more details, see xref:database-administration/aliases/manage-aliases-composite-databases.adoc#alias-management-escaping[names and escaping for database aliases targeting composite databases].
24
+
For more details, see xref:database-administration/aliases/manage-aliases-composite-databases.adoc#alias-management-escaping[database alias names that contain dots].
Copy file name to clipboardExpand all lines: modules/ROOT/pages/database-administration/composite-databases/querying-composite-databases.adoc
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,6 +14,10 @@ The examples featured in this section make use of the two Cypher clauses: link:{
14
14
15
15
The following set-up is required to recreate the examples on this page:
16
16
17
+
[.tabbed-example]
18
+
====
19
+
[role=include-with-cypher-5]
20
+
=====
17
21
.Create a standard database `movies2022`
18
22
[source, cypher]
19
23
----
@@ -42,6 +46,43 @@ CREATE ALIAS `cineasts`.`upcoming`
42
46
USER neo4j
43
47
PASSWORD 'password'
44
48
----
49
+
[NOTE]
50
+
Cypher 5 is the version that is in use in Neo4j up to and including version 2025.05.
51
+
For details, see xref:introduction.adoc#_cypher_versions[Cypher® versions].
52
+
=====
53
+
[role=include-with-cypher-25 label--new-2025.06]
54
+
=====
55
+
.Create a standard database `movies2022`
56
+
[source, cypher]
57
+
----
58
+
CREATE DATABASE movies2022
59
+
----
60
+
61
+
.Create a composite database `cineasts`
62
+
[source, cypher]
63
+
----
64
+
CREATE COMPOSITE DATABASE cineasts
65
+
----
66
+
67
+
.Create database alias `cineasts.latest` for a local database in a composite database
68
+
[source, cypher]
69
+
----
70
+
CREATE ALIAS `cineasts.latest`
71
+
FOR DATABASE movies2022
72
+
----
73
+
74
+
.Create database alias `cineasts.upcoming` for a remote database in a composite database
75
+
[source, cypher]
76
+
----
77
+
CREATE ALIAS `cineasts.upcoming`
78
+
FOR DATABASE upcoming
79
+
AT 'neo4j+s://location:7687'
80
+
USER neo4j
81
+
PASSWORD 'password'
82
+
----
83
+
=====
84
+
====
85
+
45
86
46
87
For more information about composite databases and database aliases in composite databases, see xref:database-administration/composite-databases/concepts.adoc[], and xref:database-administration/aliases/manage-aliases-composite-databases.adoc[].
0 commit comments