Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions src/main/asciidoc/reference/cypher/cypher-clauses.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,10 @@ RETURN p.name AS personName, p.age AS personAge
MATCH (a:Person)-[r:KNOWS]->(b:Person)
RETURN *

// All variables plus more items
MATCH (a:Person)-[r:KNOWS]->(b:Person)
RETURN *, a.name + ' knows ' + b.name AS sentence

// Return expressions
MATCH (p:Person)
RETURN p.name, toUpper(p.city) AS upperCity
Expand All @@ -451,6 +455,14 @@ RETURN count(DISTINCT n) AS uniqueCount, sum(DISTINCT n) AS uniqueSum
RETURN abs(-42), sqrt(16), range(1, 5)
----

`RETURN *` stands for every variable in scope at the `RETURN`, including the columns a `CALL { ... }` subquery returns
(also when the subquery itself ends in `RETURN *`). Items written after the star are added to those columns, and the
query works the same with `DISTINCT` and with aggregations: `RETURN *, count(*) AS c` groups by every variable in scope.
An item named like one of the star's variables (`RETURN *, b.name AS b`) is refused as a column defined twice, as in
Neo4j. When the variables in scope are only known at run time (after `CALL ... YIELD *` of a user function, whose output
no signature declares), the star is resolved while the query runs, and an aggregation over it is refused: list the
grouping keys explicitly. _(Since v26.12.1; before, the items after the star were dropped.)_

TIP: In a read-only query with `RETURN DISTINCT`, the clauses after the last one that binds a returned variable
(`MATCH`, `OPTIONAL MATCH`, `UNWIND`, a `WITH` that only passes variables on) can only keep or drop a row. ArcadeDB
runs them as a filter: it stops at the first match for each row and skips rows whose returned values it already
Expand Down
5 changes: 4 additions & 1 deletion src/main/asciidoc/reference/sql/sql-projections.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,10 @@ SELECT *, "hey" AS name FROM Foo

will return `[{"@type":"Foo", "@rid":"#12:0", "name":"hey"}]`

NOTE: `*` is accepted only as the first projection item: `SELECT "hey" AS name, * FROM Foo` is a syntax error.
`*` can appear at any position of the projection, and more than once: `SELECT "hey" AS name, * FROM Foo` returns the
same row as the query above. The record's fields always come first in the result, whatever the position of the `*`,
and an explicit item still wins over a field of the same name. The same holds for the `RETURN` projection of `INSERT`,
`UPDATE` and `DELETE`. _(Since v26.12.1; before, `*` was accepted only as the first item.)_

IMPORTANT: When saving back a record with a valid rid, you will overwrite the existing record!
So pay attention when using `*` together with other projections.
Expand Down
Loading