|
15 | 15 | | `right(s, n)` | Last n characters | `right('hello', 2)` → `'lo'` | |
16 | 16 | | `split(s, delim)` | Split into list | `split('a,b,c', ',')` → `['a','b','c']` | |
17 | 17 | | `reverse(s)` | Reverse string | `reverse('hello')` → `'olleh'` | |
| 18 | +| `length(s)` | String length | `length('hello')` → `5` | |
| 19 | +| `size(s)` | String length (alias) | `size('hello')` → `5` | |
18 | 20 | | `toString(x)` | Convert to string | `toString(123)` → `'123'` | |
19 | 21 |
|
20 | 22 | ## String Predicates |
|
39 | 41 | | `log10(n)` | Base-10 logarithm | `log10(100)` → `2` | |
40 | 42 | | `exp(n)` | e^n | `exp(1)` → `2.718...` | |
41 | 43 | | `rand()` | Random 0-1 | `rand()` → `0.42...` | |
| 44 | +| `random()` | Random 0-1 (alias) | `random()` → `0.42...` | |
42 | 45 | | `pi()` | π constant | `pi()` → `3.14159...` | |
43 | 46 | | `e()` | e constant | `e()` → `2.71828...` | |
44 | 47 |
|
|
93 | 96 | |----------|-------------|---------| |
94 | 97 | | `nodes(path)` | Get all nodes in path | `nodes(p)` | |
95 | 98 | | `relationships(path)` | Get all relationships | `relationships(p)` | |
| 99 | +| `rels(path)` | Get all relationships (alias) | `rels(p)` | |
96 | 100 | | `length(path)` | Path length (edges) | `length(p)` | |
97 | 101 |
|
98 | 102 | ## Type Conversion |
|
113 | 117 | | `time()` | Current time | `time()` | |
114 | 118 | | `timestamp()` | Unix timestamp (ms) | `timestamp()` | |
115 | 119 | | `localdatetime()` | Local datetime | `localdatetime()` | |
| 120 | +| `randomUUID()` | Generate random UUID | `randomUUID()` → `'550e8400-e29b-...'` | |
116 | 121 |
|
117 | 122 | ## Predicate Functions |
118 | 123 |
|
|
130 | 135 | | Function | Description | Example | |
131 | 136 | |----------|-------------|---------| |
132 | 137 | | `reduce(acc = init, x IN list \| expr)` | Fold/reduce | `reduce(s = 0, x IN [1,2,3] \| s + x)` → `6` | |
| 138 | + |
| 139 | +## CASE Expressions |
| 140 | + |
| 141 | +### Searched CASE |
| 142 | + |
| 143 | +Evaluates conditions in order and returns the first matching result: |
| 144 | + |
| 145 | +```cypher |
| 146 | +RETURN CASE |
| 147 | + WHEN n.age < 18 THEN 'minor' |
| 148 | + WHEN n.age < 65 THEN 'adult' |
| 149 | + ELSE 'senior' |
| 150 | +END AS category |
| 151 | +``` |
| 152 | + |
| 153 | +### Simple CASE |
| 154 | + |
| 155 | +Compares an expression against values: |
| 156 | + |
| 157 | +```cypher |
| 158 | +RETURN CASE n.status |
| 159 | + WHEN 'A' THEN 'Active' |
| 160 | + WHEN 'I' THEN 'Inactive' |
| 161 | + WHEN 'P' THEN 'Pending' |
| 162 | + ELSE 'Unknown' |
| 163 | +END AS status_name |
| 164 | +``` |
| 165 | + |
| 166 | +## Comprehensions |
| 167 | + |
| 168 | +### List Comprehension |
| 169 | + |
| 170 | +Create lists by transforming or filtering: |
| 171 | + |
| 172 | +```cypher |
| 173 | +// Transform each element |
| 174 | +RETURN [x IN range(1, 5) | x * 2] |
| 175 | +// → [2, 4, 6, 8, 10] |
| 176 | +
|
| 177 | +// Filter elements |
| 178 | +RETURN [x IN range(1, 10) WHERE x % 2 = 0] |
| 179 | +// → [2, 4, 6, 8, 10] |
| 180 | +
|
| 181 | +// Filter and transform |
| 182 | +RETURN [x IN range(1, 10) WHERE x % 2 = 0 | x * x] |
| 183 | +// → [4, 16, 36, 64, 100] |
| 184 | +``` |
| 185 | + |
| 186 | +### Pattern Comprehension |
| 187 | + |
| 188 | +Extract data from pattern matches within an expression: |
| 189 | + |
| 190 | +```cypher |
| 191 | +// Collect names of friends |
| 192 | +MATCH (p:Person) |
| 193 | +RETURN p.name, [(p)-[:KNOWS]->(friend) | friend.name] AS friends |
| 194 | +
|
| 195 | +// With filtering |
| 196 | +RETURN [(p)-[:KNOWS]->(f:Person) WHERE f.age > 21 | f.name] AS adult_friends |
| 197 | +``` |
| 198 | + |
| 199 | +### Map Projection |
| 200 | + |
| 201 | +Create maps by selecting properties from nodes: |
| 202 | + |
| 203 | +```cypher |
| 204 | +// Select specific properties |
| 205 | +MATCH (n:Person) |
| 206 | +RETURN n {.name, .age} |
| 207 | +// → {name: "Alice", age: 30} |
| 208 | +
|
| 209 | +// Include computed values |
| 210 | +MATCH (n:Person) |
| 211 | +RETURN n {.name, status: 'active', upperName: toUpper(n.name)} |
| 212 | +``` |
0 commit comments