Skip to content

Commit d6c403d

Browse files
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]>
1 parent 384542a commit d6c403d

File tree

3 files changed

+66
-12
lines changed

3 files changed

+66
-12
lines changed

modules/ROOT/pages/clauses/use.adoc

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,38 @@ It is supported for queries and schema commands.
1010
[[query-use-syntax]]
1111
== Syntax
1212

13-
The `USE` clause can only appear as the prefix of schema commands, or as the first clause of queries:
14-
1513
[source, syntax, role="noheader"]
1614
----
17-
USE <graph>
15+
USE <graph reference>
1816
<other clauses>
1917
----
2018

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>)`.
2227

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].
2329

24-
[[query-use-syntax-composite]]
25-
=== Composite database syntax
30+
== USE clause when connected to a standard or system database
2631

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.
2834

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).
2945
* Union parts:
3046
+
3147
[source, syntax, role="noheader"]
@@ -49,8 +65,6 @@ CALL () {
4965
+
5066
In subqueries, a `USE` clause may appear directly following the xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause]: `CALL () { ... }`.
5167

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-
5468

5569
[[query-use-examples]]
5670
== Examples
@@ -118,9 +132,6 @@ MATCH (n) RETURN n
118132

119133
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.
120134

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-
124135
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.
125136

126137
.Query

modules/ROOT/pages/deprecations-additions-removals-compatibility.adoc

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,27 @@ Several xref:clauses/transaction-clauses.adoc#query-listing-transactions[`SHOW
152152
* `startTime` and `currentQueryStartTime` now return a `ZONED DATETIME` instead of a `STRING` representation of a temporal value.
153153
* `clientAddress` and `outerTransactionId` now return `null` instead of an empty `STRING` when unavailable.
154154
* 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:
169+
170+
* `++USE graph.byName('`tom``s-database`')++`
171+
172+
* `++USE graph.propertiesByName('database.with.dot')++`
173+
174+
Note that escaping graph names within the graph functions string argument is not supported in Cypher 5.
175+
155176
|===
156177

157178
=== New features

modules/ROOT/pages/queries/expressions.adoc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,25 @@ String literals can contain the following escape sequences:
8282
* A predicate expression (i.e. an expression returning a `BOOLEAN` value): `a.prop = 'Hello'`, `length(p) > 10`, `a.name IS NOT NULL`.
8383
* Label and relationship type expressions: `(n:A|B)`, `+()-[r:R1|R2]->()+`.
8484
* `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`.
105+
106+

0 commit comments

Comments
 (0)