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
add graph reference section to expressions (#1162)
* adds section about graph references to expressions
* attempt to split behavior of use clauses in the docs depending on
which database you're connected to
---------
Co-authored-by: Jens Pryce-Åklundh <[email protected]>
Copy file name to clipboardExpand all lines: modules/ROOT/pages/clauses/use.adoc
+23-12Lines changed: 23 additions & 12 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,22 +10,38 @@ It is supported for queries and schema commands.
10
10
[[query-use-syntax]]
11
11
== Syntax
12
12
13
-
The `USE` clause can only appear as the prefix of schema commands, or as the first clause of queries:
14
-
15
13
[source, syntax, role="noheader"]
16
14
----
17
-
USE <graph>
15
+
USE <graph reference>
18
16
<other clauses>
19
17
----
20
18
21
-
Where `<graph>` refers to the name or alias of a database in the DBMS.
19
+
A graph reference can be described using:
20
+
21
+
* Direct graph references: `USE db1`.
22
+
* The graph function xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId()`], to access a graph of a given element: `USE graph.byName(<element-id-string>)`.
23
+
24
+
When connected to a composite database, a graph reference may additionally be passed with:
25
+
26
+
* The graph function xref:functions/graph.adoc#functions-graph-byname[`graph.byName()`], which allows the graph reference to be resolved dynamically: `USE graph.byName(<string-expression>)`.
22
27
28
+
A more detailed description of how and when a graph references needs to be quoted and/or escaped is defined xref::queries/expressions.adoc#graphreferences[here].
23
29
24
-
[[query-use-syntax-composite]]
25
-
=== Composite database syntax
30
+
== USE clause when connected to a standard or system database
26
31
27
-
When running queries against a link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/composite-databases/concepts/[composite database], the `USE` clause can also appear as the first clause of:
32
+
All databases and aliases are valid graph reference targets except link:operations-manual/current/database-administration/aliases/manage-aliases-composite-databases/[composite databases and their constituents].
33
+
Targeting multiple databases is not allowed, unless connected to a composite database.
28
34
35
+
=== Position of use clauses
36
+
When connected to a non-composite database, the `USE` clause can only appear as the prefix of schema commands, or as the first clause of queries. There may be multiple `USE` clauses as long as they target the same database.
37
+
38
+
== USE clause when connected to a composite database
39
+
When executing queries against a link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/composite-databases/concepts/[composite database], the `USE` clause must only refer to graphs that are part of the current composite database. The constituents can be listed either with `RETURN graph.names()` when connected to the composite database or `SHOW DATABASES YIELD name, constituents RETURN *`.
40
+
41
+
=== Position of use clauses
42
+
When running queries against a composite database, the `USE` clause can appear as the first clause of:
43
+
44
+
* A query (similar to how it is used when connected to a non-composite database).
29
45
* Union parts:
30
46
+
31
47
[source, syntax, role="noheader"]
@@ -49,8 +65,6 @@ CALL () {
49
65
+
50
66
In subqueries, a `USE` clause may appear directly following the xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause]: `CALL () { ... }`.
51
67
52
-
When executing queries against a composite database, the `USE` clause must only refer to graphs that are part of the current composite database.
53
-
54
68
55
69
[[query-use-examples]]
56
70
== Examples
@@ -118,9 +132,6 @@ MATCH (n) RETURN n
118
132
119
133
The xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId()`] function can be used in the `USE` clause to resolve a constituent graph to which a given xref:functions/scalar.adoc#functions-elementid[element id] belongs.
120
134
121
-
[NOTE]
122
-
On a standard database, a `USE` clause with `graph.byElementId()` cannot be combined with other `USE` clauses unless the subsequent `USE` clauses reference the same element id.
123
-
124
135
In the below example, it is assumed that the DBMS contains the database corresponding to the given element id. If you are connected to a composite database it needs to be a element id to a constituent database, which is a standard database in the DBMS.
Copy file name to clipboardExpand all lines: modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc
+21Lines changed: 21 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -152,6 +152,27 @@ Several xref:clauses/transaction-clauses.adoc#query-listing-transactions[`SHOW
152
152
* `startTime` and `currentQueryStartTime` now return a `ZONED DATETIME` instead of a `STRING` representation of a temporal value.
153
153
* `clientAddress` and `outerTransactionId` now return `null` instead of an empty `STRING` when unavailable.
154
154
* The current query-related columns — `currentQuery`, `currentQueryId`, `parameters`, `planner`, `runtime`, `indexes`, `currentQueryStartTime`, `currentQueryElapsedTime`, `currentQueryCpuTime`, `currentQueryIdleTime`, and `currentQueryStatus` — now return `null` when no query is executing.
155
+
156
+
a|
157
+
label:functionality[]
158
+
label:updated[]
159
+
[source, cypher, role="noheader"]
160
+
----
161
+
USE graph.byName('tom`s-database')
162
+
163
+
USE graph.propertiesByName('database.with.dot')
164
+
----
165
+
| xref::queries/expressions.adoc#graphreferences[Graph references] in arguments of the functions xref:functions/graph.adoc#functions-graph-byname[`graph.byName`] and xref:functions/graph.adoc#functions-graph-propertiesByName[`graph.propertiesByName`] in Cypher 25 are parsed as `<symbolic-name>` or `<symbolic-name>.<symbolic-name>` and now support escaping names.
166
+
For more information, see xref:syntax/expressions.adoc#graph-references[Cypher expressions -> Graph references.
167
+
Graph name parts that contain unsupported characters for unescaped symbolic names now require backtick quoting.
168
+
Graph name parts with special characters may require additional escaping of those characters:
Copy file name to clipboardExpand all lines: modules/ROOT/pages/queries/expressions.adoc
+22Lines changed: 22 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -82,3 +82,25 @@ String literals can contain the following escape sequences:
82
82
* A predicate expression (i.e. an expression returning a `BOOLEAN` value): `a.prop = 'Hello'`, `length(p) > 10`, `a.name IS NOT NULL`.
83
83
* Label and relationship type expressions: `(n:A|B)`, `+()-[r:R1|R2]->()+`.
84
84
* `null`.
85
+
86
+
[[graph-references]]
87
+
== Graph references
88
+
* Database and alias names when managing link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/[databases and aliases]: `CREATE DATABASE <symbolic-name>`.
89
+
* Static graph references: `USE <symbolic-name>` or `USE <symbolic-name>.<symbolic-name>` (for constituents of a link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/composite-databases/concepts/[composite databases]).
90
+
* Dynamic graph reference with the xref:functions/graph.adoc#functions-graph-byname[`graph.byName`] function, to access a graph of a given name: `USE graph.byName(<string-expression>)`.
91
+
* Dynamic graph references with the xref:functions/graph.adoc#functions-graph-by-elementid[`graph.byElementId`] function, to access a graph of a given node or relationship: `USE graph.byName(<element-id-string>)`.
92
+
* Retrieving properties of a graph with the xref:functions/graph.adoc#functions-graph-propertiesByName[`graph.propertiesByName`] function: `graph.propertiesByName(<string-expression>)`.
93
+
94
+
95
+
Rules on string expressions for graph references when using identifiers (static graph references, administration commands) or a string (graph.byName function):
96
+
97
+
* Unquoted dots are separators between a composite database and its constituent.
98
+
For example, `composite.db1` represents the constituent `composite.db1` in the composite database `composite`.
99
+
To refer to a database with a dot (`.`) in its name, quote the graph reference instead: `++`composite.db1`++`.
100
+
* When resolving a graph reference within a graph function, the string argument is parsed like a static graph reference.
101
+
Thus, `USE graph.byName(<graph-reference>)` is typically equivalent to `USE <graph-reference>`.
102
+
However, escaping rules for xref::syntax/naming.adoc#symbolic-names-escaping-rules[symbolic names] are applied to the argument.
103
+
For string literals, both the escaping rules for xref:queries/expressions.adoc#expressions-string-literals[string literals] (during query parsing) and xref::syntax/naming.adoc#symbolic-names-escaping-rules[symbolic names] (during graph reference evaluation) are applied.
104
+
For example, the graph reference in `USE graph.byName('+composite.1\\u0041+')` resolves to the constituent `composite.1a` of the composite database `composite`.
0 commit comments