diff --git a/src/main/asciidoc/reference/cypher/cypher-clauses.adoc b/src/main/asciidoc/reference/cypher/cypher-clauses.adoc index 54e7a783..1181fb00 100644 --- a/src/main/asciidoc/reference/cypher/cypher-clauses.adoc +++ b/src/main/asciidoc/reference/cypher/cypher-clauses.adoc @@ -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 @@ -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 diff --git a/src/main/asciidoc/reference/sql/sql-projections.adoc b/src/main/asciidoc/reference/sql/sql-projections.adoc index 20576741..46244cca 100644 --- a/src/main/asciidoc/reference/sql/sql-projections.adoc +++ b/src/main/asciidoc/reference/sql/sql-projections.adoc @@ -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.