Skip to content

Commit 975bf2c

Browse files
committed
Update detailed description section on 'Database alias names that contain dots'
1 parent 69c804f commit 975bf2c

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
@@ -52,7 +52,7 @@ For a description of all the returned columns of this command, and for ways in w
5252

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

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

5757
The namespace must be the name of the composite database.
5858

@@ -214,12 +214,158 @@ SHOW DATABASE garden YIELD name, type, constituents
214214
----
215215

216216
[[alias-management-escaping]]
217-
== Database alias names and escaping
217+
== Database alias names that contain dots
218218

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

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
223369

224370
The composite database name and the database alias name need to be quoted individually.
225371
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`++`.
@@ -236,18 +382,18 @@ CREATE DATABASE `northwind-graph`;
236382
.Query
237383
[source, cypher]
238384
----
239-
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`
240386
----
241387

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

244390
.Query
245391
[source, cypher]
246392
----
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`
248394
----
249395

250-
=== Handling multiple dots
396+
==== Handling multiple dots
251397

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

@@ -257,18 +403,18 @@ Though these always need to be quoted in order to avoid ambiguity with the compo
257403
.Query
258404
[source, cypher, role=test-skip]
259405
----
260-
CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
406+
CYPHER 5 CREATE ALIAS `my.alias.with.dots` FOR DATABASE `northwind-graph`
261407
----
262408

263409
.Query
264410
[source, cypher, role=test-skip]
265411
----
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`
267413
----
268414

269415

270416
[role=label--deprecated]
271-
=== Single dots and local database aliases
417+
==== Single dots and local database aliases
272418

273419
There is a special case for local database aliases with a single dot without any existing composite database.
274420
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
277423
.Query
278424
[source, cypher]
279425
----
280-
CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
426+
CYPHER 5 CREATE ALIAS some.alias FOR DATABASE `northwind-graph`
281427
----
282428

283-
=== Handling parameters
429+
==== Handling parameters
284430

285431
When using parameters, names cannot be quoted.
286432
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:
298444
.Query
299445
[source, cypher]
300446
----
301-
CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
447+
CYPHER 5 CREATE ALIAS $aliasname FOR DATABASE `northwind-graph`
302448
----
303449

304450
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
320466

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

323-
=== Handling parameters
469+
==== Handling parameters
324470

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

@@ -329,8 +475,8 @@ Consider the setup:
329475
.Query
330476
[source, cypher, role="noheader test-skip"]
331477
----
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`
334480
----
335481

336482
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:
348494
.Query
349495
[source, cypher, role=test-fail]
350496
----
351-
DROP ALIAS $aliasname FOR DATABASE
497+
CYPHER 5 DROP ALIAS $aliasname FOR DATABASE
352498
----
353499

354500
.Error message

0 commit comments

Comments
 (0)