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
+
=== Conflicting names
232
+
Before Neo4j 2025.06 it was 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`.
233
+
Both of these would be referred to by the same name `garden.flowers`.
234
+
235
+
Neo4j 2025.06 ensures that no such conflicts exist and will throw an exception when attempting to create a new alias with the same name as an existing alias.
236
+
237
+
[.tabbed-example]
238
+
=====
239
+
[role=include-with-cypher-5]
240
+
======
241
+
Creating a regular alias with the same name as an existing composite constituent is disallowed:
242
+
243
+
.Query
244
+
[source, cypher]
245
+
----
246
+
CYPHER 5 CREATE COMPOSITE DATABASE `garden`
247
+
CYPHER 5 CREATE ALIAS `garden`.`flowers` FOR DATABASE `northwind-graph`
248
+
CYPHER 5 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
249
+
----
250
+
251
+
.Error message
252
+
[source, output, role="noheader"]
253
+
----
254
+
Failed to create the specified database alias 'garden.flowers': Database name or alias already exists.
255
+
----
256
+
257
+
======
258
+
259
+
[role=include-with-cypher-25 label--new-2025.06]
260
+
======
261
+
262
+
Creating a regular alias with the same name as an existing composite constituent is disallowed.
263
+
The Cypher 25 syntax makes no distinction between the names to clarify that they are considered equivalent.
264
+
265
+
.Query
266
+
[source, cypher]
267
+
----
268
+
CYPHER 25 CREATE COMPOSITE DATABASE `garden`
269
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
270
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
271
+
----
272
+
273
+
.Error message
274
+
[source, output, role="noheader"]
275
+
----
276
+
Failed to create the specified database alias 'garden.flowers': Database name or alias already exists.
277
+
----
278
+
======
279
+
=====
280
+
281
+
[.tabbed-example]
282
+
=====
283
+
[role=include-with-cypher-5]
284
+
======
285
+
Creating a composite constituent with the same name as an existing non-composite alias is disallowed. This example scenario is prevented already on the second line, thus the constituent on the third line cannot be created.
286
+
287
+
.Query
288
+
[source, cypher]
289
+
----
290
+
CYPHER 5 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
291
+
CYPHER 5 CREATE COMPOSITE DATABASE `garden`
292
+
CYPHER 5 CREATE ALIAS `garden`.`flowers` FOR DATABASE `northwind-graph`
293
+
----
294
+
295
+
.Error message
296
+
[source, output, role="noheader"]
297
+
----
298
+
Cannot create database 'garden' because another database 'garden.flowers' exists with an ambiguous name.
299
+
----
300
+
301
+
======
302
+
303
+
[role=include-with-cypher-25 label--new-2025.06]
304
+
======
305
+
306
+
Creating a composite constituent with the same name as an existing non-composite alias is disallowed.
307
+
This example scenario is prevented already on the second line, thus the constituent on the third line cannot be created.
308
+
The Cypher 25 syntax makes no distinction between the names to clarify that they are considered equivalent.
309
+
310
+
.Query
311
+
[source, cypher]
312
+
----
313
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
314
+
CYPHER 25 CREATE COMPOSITE DATABASE `garden`
315
+
CYPHER 25 CREATE ALIAS `garden.flowers` FOR DATABASE `northwind-graph`
316
+
----
317
+
318
+
.Error message
319
+
[source, output, role="noheader"]
320
+
----
321
+
Cannot create database 'garden' because another database 'garden.flowers' exists with an ambiguous name.
322
+
----
323
+
======
324
+
=====
325
+
326
+
327
+
Creating a composite constituent with the same name as an existing non-composite alias is disallowed:
328
+
329
+
=== Cypher 25 specific behaviour
330
+
==== Accessing an existing alias with dots
331
+
332
+
Cypher 25 relies on the guarantee that no conflicting names are allowed in Neo4j 2025.06 and later.
333
+
The following queries all act on the same alias, regardless if that alias is a composite constituent or not.
334
+
The special quoting of separate name parts that was necessary in Cypher 5 is not necessary / permitted in Cypher 25.
335
+
336
+
.Parameters
337
+
[source, javascript]
338
+
----
339
+
{
340
+
"name": "my.garden.beautiful.flowers"
341
+
}
342
+
----
343
+
.Query
344
+
[source, cypher]
345
+
----
346
+
CYPHER 25 ALTER ALIAS `my.garden.beautiful.flowers` SET DATABASE PROPERTIES { perennial: true }
347
+
CYPHER 25 ALTER ALIAS $name SET DATABASE PROPERTIES { perennial: true }
348
+
CYPHER 25 USE `my.garden.beautiful.flowers` RETURN 1
349
+
----
350
+
351
+
==== Creating a new alias with dots
352
+
During `CREATE`, Cypher25 will split the given name on each dot, left to right, and check if a corresponding composite database exists.
353
+
If no composite database is found, Cypher25 will fall back to creating a regular non-composite alias instead.
354
+
355
+
The following query attempts to create in order:
356
+
357
+
* Constituent alias `garden.beautiful.flowers` within composite database `my`.
358
+
* Constituent alias `beautiful.flowers` within composite database `my.garden`.
359
+
* Constituent alias `flowers` within composite database `my.garden.beautiul`.
360
+
* Regular non-composite alias `my.garden.beautiful.flowers`.
361
+
362
+
.Query
363
+
[source, cypher]
364
+
----
365
+
CYPHER 25 CREATE COMPOSITE DATABASE `my.garden`
366
+
CYPHER 25 CREATE ALIAS `my.garden.beautiful.flowers` FOR DATABASE `northwind-graph`
367
+
----
368
+
Since it finds the composite database `my.garden` it will create the constituent alias `beautiful.flowers` within the found composite.
369
+
370
+
371
+
372
+
=== Cypher 5 specific behaviour
373
+
374
+
==== Quoting database alias and composite database names
229
375
230
376
The composite database name and the database alias name need to be quoted individually.
231
377
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`++`.
CREATE ALIAS `my-composite-database-with-dashes`.`my alias with spaces` FOR DATABASE `northwind-graph`
391
+
CYPHER 5 CREATE ALIAS `my-composite-database-with-dashes`.`my alias with spaces` FOR DATABASE `northwind-graph`
246
392
----
247
393
248
394
When not quoted individually, a database alias with the full name `my alias with.dots and spaces` gets created instead:
249
395
250
396
.Query
251
397
[source, cypher]
252
398
----
253
-
CREATE ALIAS `my alias with.dots and spaces` FOR DATABASE `northwind-graph`
399
+
CYPHER 5 CREATE ALIAS `my alias with.dots and spaces` FOR DATABASE `northwind-graph`
254
400
----
255
401
256
-
=== Handling multiple dots
402
+
==== Handling multiple dots
257
403
258
404
//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
405
@@ -263,18 +409,18 @@ Though these always need to be quoted in order to avoid ambiguity with the compo
263
409
.Query
264
410
[source, cypher, role=test-skip]
265
411
----
266
-
CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
412
+
CYPHER 5 CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
267
413
----
268
414
269
415
.Query
270
416
[source, cypher, role=test-skip]
271
417
----
272
-
CREATE ALIAS `my.composite.database.with.dots`.`my.other.alias.with.dots` FOR DATABASE `northwind-graph`
418
+
CYPHER 5 CREATE ALIAS `my.composite.database.with.dots`.`my.other.alias.with.dots` FOR DATABASE `northwind-graph`
273
419
----
274
420
275
421
276
422
[role=label--deprecated]
277
-
=== Single dots and local database aliases
423
+
==== Single dots and local database aliases
278
424
279
425
There is a special case for local database aliases with a single dot without any existing composite database.
280
426
If a composite database `some` exists, the query below will create a database alias named `alias` within the composite database `some`.
@@ -283,10 +429,10 @@ If no such database exists, however, the same query will instead create a databa
283
429
.Query
284
430
[source, cypher]
285
431
----
286
-
CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
432
+
CYPHER 5 CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
287
433
----
288
434
289
-
=== Handling parameters
435
+
==== Handling parameters
290
436
291
437
When using parameters, names cannot be quoted.
292
438
When the given parameter includes dots, the first dot will be considered the divider for the composite database.
@@ -304,7 +450,7 @@ Consider the query with parameter:
304
450
.Query
305
451
[source, cypher]
306
452
----
307
-
CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
453
+
CYPHER 5 CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
308
454
----
309
455
310
456
If the composite database `mysimplecompositedatabase` exists, then a database alias `myalias` will be created in that composite database.
@@ -326,7 +472,7 @@ If `mycompositedatabase` does not exist, the command will create a database alia
326
472
327
473
In these cases, it is recommended to avoid parameters and explicitly quote the composite database name and alias name separately to avoid ambiguity.
328
474
329
-
=== Handling parameters
475
+
==== Handling parameters
330
476
331
477
Further special handling with parameters is needed for database aliases and similarly named composite databases.
332
478
@@ -335,8 +481,8 @@ Consider the setup:
335
481
.Query
336
482
[source, cypher, role="noheader test-skip"]
337
483
----
338
-
CREATE COMPOSITE DATABASE foo
339
-
CREATE ALIAS `foo.bar` FOR DATABASE `northwind-graph`
484
+
CYPHER 5 CREATE COMPOSITE DATABASE foo
485
+
CYPHER 5 CREATE ALIAS `foo.bar` FOR DATABASE `northwind-graph`
340
486
----
341
487
342
488
The alias `foo.bar` does not belong to the composite database `foo`.
@@ -354,7 +500,7 @@ Dropping this alias using parameters fails with an error about a missing alias:
0 commit comments