Skip to content

Commit 693d69a

Browse files
l-heemannLojjs
authored andcommitted
Update detailed description section on 'Database alias names that contain dots'
1 parent 49d24ac commit 693d69a

File tree

1 file changed

+162
-16
lines changed

1 file changed

+162
-16
lines changed

modules/ROOT/pages/database-administration/aliases/manage-aliases-composite-databases.adoc

Lines changed: 162 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ For a description of all the returned columns of this command, and for ways in w
5858

5959
Both local and remote database aliases can be part of a xref::database-administration/composite-databases/concepts.adoc[composite database].
6060

61-
The database alias is made of two parts, separated by a dot: the namespace and the alias name.
61+
The database alias consists of two parts, separated by a dot: the namespace and the alias name.
6262

6363
The namespace must be the name of the composite database.
6464

@@ -220,12 +220,158 @@ SHOW DATABASE garden YIELD name, type, constituents
220220
----
221221

222222
[[alias-management-escaping]]
223-
== Database alias names and escaping
223+
== Database alias names that contain dots
224224

225225
Naming database aliases in composite databases follows the same rule as xref:database-administration/aliases/naming-aliases.adoc[naming aliases for standard databases].
226226
However, when it comes to escaping names using backticks, there are some additional things to consider:
227227

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
229375

230376
The composite database name and the database alias name need to be quoted individually.
231377
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`++`.
@@ -242,18 +388,18 @@ CREATE DATABASE `northwind-graph`;
242388
.Query
243389
[source, cypher]
244390
----
245-
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`
246392
----
247393

248394
When not quoted individually, a database alias with the full name `my alias with.dots and spaces` gets created instead:
249395

250396
.Query
251397
[source, cypher]
252398
----
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`
254400
----
255401

256-
=== Handling multiple dots
402+
==== Handling multiple dots
257403

258404
//Examples where dots are not separators between composite name and alias name are impossible to test, because the right escaping cannot be inferred automatically.
259405

@@ -263,18 +409,18 @@ Though these always need to be quoted in order to avoid ambiguity with the compo
263409
.Query
264410
[source, cypher, role=test-skip]
265411
----
266-
CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
412+
CYPHER 5 CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
267413
----
268414

269415
.Query
270416
[source, cypher, role=test-skip]
271417
----
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`
273419
----
274420

275421

276422
[role=label--deprecated]
277-
=== Single dots and local database aliases
423+
==== Single dots and local database aliases
278424

279425
There is a special case for local database aliases with a single dot without any existing composite database.
280426
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
283429
.Query
284430
[source, cypher]
285431
----
286-
CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
432+
CYPHER 5 CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
287433
----
288434

289-
=== Handling parameters
435+
==== Handling parameters
290436

291437
When using parameters, names cannot be quoted.
292438
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:
304450
.Query
305451
[source, cypher]
306452
----
307-
CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
453+
CYPHER 5 CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
308454
----
309455

310456
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
326472

327473
In these cases, it is recommended to avoid parameters and explicitly quote the composite database name and alias name separately to avoid ambiguity.
328474

329-
=== Handling parameters
475+
==== Handling parameters
330476

331477
Further special handling with parameters is needed for database aliases and similarly named composite databases.
332478

@@ -335,8 +481,8 @@ Consider the setup:
335481
.Query
336482
[source, cypher, role="noheader test-skip"]
337483
----
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`
340486
----
341487

342488
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:
354500
.Query
355501
[source, cypher, role=test-fail]
356502
----
357-
DROP ALIAS $aliasname FOR DATABASE
503+
CYPHER 5 DROP ALIAS $aliasname FOR DATABASE
358504
----
359505

360506
.Error message

0 commit comments

Comments
 (0)