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