|
1 | | -= Expressions overview |
2 | | -:description: Overview of the expressions allowed in Cypher. |
3 | | - |
4 | | -This page contains an overview of the allowed expressions in Cypher. |
5 | | - |
6 | | -[[general]] |
7 | | -== General |
8 | | - |
9 | | -* A xref:syntax/variables.adoc[variable]: `n`, `x`, `rel`, `myFancyVariable`, `++`A name with special characters in it[]!`++`. |
10 | | -* A xref:queries/concepts.adoc[property]: `n.prop`, `x.prop`, `rel.thisProperty`, `++myFancyVariable.`(special property name)`++`. |
11 | | -For more information, see xref:values-and-types/property-structural-constructed.adoc#property-types[Values and types -> property types]. |
12 | | -* A xref:clauses/set.adoc#dynamic-set-property[dynamic property]: `n["prop"]`, `rel[n.city + n.zip]`, `map[coll[0]]`. |
13 | | -For more information, see xref:clauses/where.adoc#filter-on-dynamic-property[`WHERE` -> filter on dynamically computed properties]. |
14 | | -* A xref:syntax/parameters.adoc[parameter]: `$param`, `$0`. |
15 | | -* A xref:values-and-types/lists.adoc[list of expressions]: `['a', 'b']`, `[1, 2, 3]`, `['a', 2, n.property, $param]`, `[]`. |
16 | | -* A xref:functions/index.adoc[function] call: `length(p)`, `nodes(p)`. |
17 | | -* An xref:functions/aggregating.adoc[aggregating function] call: `avg(x.prop)`, `+count(*)+`. |
18 | | -* A xref:patterns/fixed-length-patterns.adoc#path-patterns[path-pattern]: `+(a)-[r]->(b)+`, `+(a)-[r]-(b)+`, `+(a)--(b)+`, `+(a)-->()<--(b)+`. |
19 | | -* An xref:syntax/operators.adoc[operator application]: `1 + 2`, `3 < 4`. |
20 | | -* A xref:subqueries/index.adoc[subquery expression]: `COUNT {}`, `COLLECT {}`, `EXISTS {}`, `CALL {}`. |
21 | | -* A xref:expressions/predicates/string-operators#regular-expressions[regular expression]: `a.name =~ 'Tim.*'`. |
22 | | -* A xref:expressions/conditional-expressions.adoc[`CASE` expression]. |
23 | | -* xref:values-and-types/working-with-null[`null`]. |
24 | | - |
25 | | -[NOTE] |
26 | | -==== |
27 | | -Expressions containing unsanitized user input may make your application vulnerable to Cypher injection. |
28 | | -Consider using xref:syntax/parameters.adoc[parameters] instead. |
29 | | -Learn more in link:https://neo4j.com/developer/kb/protecting-against-cypher-injection/[Protecting against Cypher Injection]. |
30 | | -==== |
31 | | - |
32 | | -[NOTE] |
33 | | -==== |
34 | | -Most expressions in Cypher evaluate to `null` if any of their inner expressions are `null`. |
35 | | -Notable exceptions are the operators `IS NULL`, `IS NOT NULL`, and the xref:expressions/predicates/type-predicate-expressions.adoc[type predicate expressions]. |
36 | | -==== |
37 | | - |
38 | | -[[numerical]] |
39 | | -== Numerical |
40 | | - |
41 | | -* A numeric (`INTEGER` or `FLOAT`) literal: `13`, `-40000`, `3.14`. |
42 | | -* A numeric (`INTEGER` or `FLOAT`) literal in scientific notation: `6.022E23`. |
43 | | -* A hexadecimal `INTEGER` literal (starting with `0x`): `0x13af`, `0xFC3A9`, `-0x66eff`. |
44 | | -* An octal `INTEGER` literal (starting with `0o`): `0o1372`, `-0o5671`. |
45 | | -* A `FLOAT` literal: `Inf`, `Infinity`, `NaN`. |
46 | | -* `null`. |
47 | | - |
48 | | -[NOTE] |
49 | | -==== |
50 | | -Any numeric literal may contain an underscore `_` between digits. |
51 | | -There may be an underscore between the `0x` or `0o` and the digits for hexadecimal and octal literals. |
52 | | -==== |
53 | | - |
54 | | -[[string]] |
55 | | -== String |
56 | | - |
57 | | -* A `STRING` literal: `'Hello'`, `"World"`. |
58 | | -* A case-sensitive `STRING` matching expression: `a.surname STARTS WITH 'Sven'`, `a.surname ENDS WITH 'son'` or `a.surname CONTAINS 'son'`. |
59 | | -* `null`. |
60 | | - |
61 | | -[[expressions-string-literals]] |
62 | | -=== String literal escape sequences |
63 | | - |
64 | | -String literals can contain the following escape sequences: |
65 | | - |
66 | | -[options="header", cols=">1,<2"] |
67 | | -|=================== |
68 | | -|Escape sequence|Character |
69 | | -|`\t`|Tab |
70 | | -|`\b`|Backspace |
71 | | -|`\n`|Newline |
72 | | -|`\r`|Carriage return |
73 | | -|`\f`|Form feed |
74 | | -|`\'`|Single quote |
75 | | -|`\"`|Double quote |
76 | | -|`\\`|Backslash |
77 | | -|`\uxxxx`|Unicode UTF-16 code point (4 hex digits must follow the `\u`) |
78 | | -|=================== |
79 | | - |
80 | | -[[boolean]] |
81 | | -== Boolean |
82 | | - |
83 | | -* A `BOOLEAN` literal: `true`, `false`. |
84 | | -* A predicate expression (i.e. an expression returning a `BOOLEAN` value): `a.prop = 'Hello'`, `length(p) > 10`, `a.name IS NOT NULL`. |
85 | | -* Label and relationship type expressions: `(n:A|B)`, `+()-[r:R1|R2]->()+`. |
86 | | -* `null`. |
87 | | - |
88 | | -[[graph-references]] |
89 | | -== Graph references |
90 | | -* Database and alias names when managing link:{neo4j-docs-base-uri}/operations-manual/current/database-administration/[databases and aliases]: `CREATE DATABASE <symbolic-name>`. |
91 | | -* 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]). |
92 | | -* 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>)`. |
93 | | -* 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>)`. |
94 | | -* Retrieving properties of a graph with the xref:functions/graph.adoc#functions-graph-propertiesByName[`graph.propertiesByName`] function: `graph.propertiesByName(<string-expression>)`. |
95 | | - |
96 | | - |
97 | | -Rules on string expressions for graph references when using identifiers (static graph references, administration commands) or a string (graph.byName function): |
98 | | - |
99 | | -* Unquoted dots are separators between a composite database and its constituent. |
100 | | -For example, `composite.db1` represents the constituent `composite.db1` in the composite database `composite`. |
101 | | -To refer to a database with a dot (`.`) in its name, quote the graph reference instead: `++`composite.db1`++`. |
102 | | -* When resolving a graph reference within a graph function, the string argument is parsed like a static graph reference. |
103 | | - Thus, `USE graph.byName(<graph-reference>)` is typically equivalent to `USE <graph-reference>`. |
104 | | - However, escaping rules for xref::syntax/naming.adoc#symbolic-names-escaping-rules[symbolic names] are applied to the argument. |
105 | | - For string literals, both the escaping rules for xref:expressions/expressions-overview.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. |
106 | | -For example, the graph reference in `USE graph.byName('+composite.1\\u0041+')` resolves to the constituent `composite.1a` of the composite database `composite`. |
107 | | - |
108 | 1 |
|
0 commit comments