Skip to content

Commit 524f4db

Browse files
committed
add graph reference section to expressions
1 parent ef1b7be commit 524f4db

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

modules/ROOT/pages/clauses/use.adoc

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,39 @@ 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
31+
=== Allowed graph reference targets
2632

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:
33+
All databases except composite databases can be targeted. It is not possible to target more than one database. This is only possible when 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+
=== Allowed graph reference targets
40+
When executing queries against a 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 *`.
41+
42+
=== Position of use clauses
43+
When running queries against a link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/composite-databases/concepts/[composite database], the `USE` clause can appear as the first clause of:
44+
45+
* a query (as when connected to a non-composite database)
2946
* Union parts:
3047
+
3148
[source, syntax, role="noheader"]
@@ -49,8 +66,6 @@ CALL () {
4966
+
5067
In subqueries, a `USE` clause may appear directly following the xref:subqueries/call-subquery.adoc#variable-scope-clause[variable scope clause]: `CALL () { ... }`.
5168

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

5570
[[query-use-examples]]
5671
== Examples
@@ -118,9 +133,6 @@ MATCH (n) RETURN n
118133

119134
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.
120135

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-
124136
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.
125137

126138
.Query

modules/ROOT/pages/queries/expressions.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,21 @@ 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+
[[graphreferences]]
87+
== Graph references
88+
* static graph references: `USE <symbolic-name>` (for standard and system databases), `USE <symbolic-name>.<symbolic-name>` (for composite databases)
89+
* 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>)`
90+
* dynamic graph reference 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>)`
91+
92+
Rules on string expressions for graph references when using identifiers (static graph references, administration commands) or a string (graph.byName function):
93+
94+
* Unquoted dots are separators between a composite database and its constituent. For example, `composite.db1` represents the constituent composite.db1 in the composite database composite. To refer to a database with a dot in its name, quote the graph reference instead: `+`composite.db1`+`
95+
* When resolving a graph reference within a graph function, the string argument is parsed the same as a static graph reference before resolving it. This means that for most arguments, `USE graph.byName(<graph-reference>)` is equal to `USE <graph-reference>`. However, escaping rules for xref::syntax/naming.adoc#symbolic-names-escaping-rules[symbolic names] are applied to the argument. When passing in a string literal, this means both the escaping rules for xref:queries/expressions.adoc#expressions-string-literals[string literals] (when parsing the query) as well as the escaping rules for xref::syntax/naming.adoc#symbolic-names-escaping-rules[symbolic names] (when evaluating the graph reference) are applied. For example, the graph reference in `USE graph.byName('+composite.1\\u0041+')` will resolve to the constituent `composite.1a` of the composite database `composite`.
96+
97+
Graph references are used within:
98+
99+
* xref:clauses/use.adoc[`USE clauses`]
100+
* database and alias names when managing databases and aliases, see link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/[Database administration]
101+
102+

0 commit comments

Comments
 (0)