pub struct GroupingSyntax {
pub grouping_sets: bool,
pub with_rollup: bool,
pub order_by_using: bool,
pub group_by_all: bool,
pub group_by_set_quantifier: bool,
pub order_by_all: bool,
}Expand description
Dialect-owned GROUP BY / ORDER BY grouping-and-ordering syntax accepted by the
parser.
The grouping-set constructs and the clause-level grouping/ordering modes and
quantifiers. Split out of SelectSyntax at its 16-field line as the
grouping/ordering axis, distinct from the SELECT-core and query-tail axes. Each
flag is a grammar gate: when off the keyword falls through to the ordinary
expression/grouping-item grammar or surfaces as a clean parse error.
Fields§
§grouping_sets: boolAccept the SQL:1999 (feature T431) grouping-set constructs as GROUP BY
items: ROLLUP (…), CUBE (…), GROUPING SETS (…), and the empty grouping
set (). PostgreSQL lowers these in GROUP BY item position for any case
spelling — an unquoted rollup (a, b) is the grouping construct, never a
call to a user function rollup (quote it, "rollup"(a, b), to call the
function) — so the parser models them as GroupByItem
nodes, not FunctionCall expressions. When off,
the keywords fall through to the expression grammar (an ordinary function
call), which is how MySQL reads them; MySQL’s own grouping surface is the
distinct trailing WITH ROLLUP, not modelled here. On for ANSI (the T431
standard) / PostgreSQL / Lenient, off for MySQL.
with_rollup: boolAccept MySQL’s trailing GROUP BY <keys> WITH ROLLUP modifier — MySQL’s only
grouping-set surface (it has no SQL:1999 ROLLUP (…) item form). It is a
spelling of the same super-aggregate as ROLLUP (…), so it canonicalizes
into the one GroupByItem::Rollup shape tagged
RollupSpelling::WithRollup — never a
new node. When off, the trailing WITH ROLLUP is left unconsumed and surfaces
as a clean parse error; PostgreSQL/ANSI spell the construct ROLLUP (…), so
accepting WITH ROLLUP there would be an over-acceptance. On for MySQL /
Lenient, off elsewhere. (MySQL 8.0.1+ also permits WITH ROLLUP alongside
ORDER BY; older versions did not — a version wrinkle we do not model.)
order_by_using: boolAccept PostgreSQL’s ORDER BY <expr> USING <operator> sort form (gram.y
sortby: a_expr USING qual_all_Op opt_nulls_order), which sorts by a named
ordering operator (USING <, USING OPERATOR(schema.op)) instead of
ASC/DESC. PostgreSQL-only; ANSI and MySQL have only ASC/DESC, so there
the USING keyword is left unconsumed and surfaces as a trailing-input parse
error — the same reject mechanism the other unsupported clauses use.
group_by_all: boolAccept DuckDB’s GROUP BY ALL clause mode: group by every non-aggregated
projection column, resolved at bind time
(Select::group_by_all — a mode with an empty key
list, never a GroupByItem). ALL cannot mix
with explicit keys or grouping sets (DuckDB syntax-errors on GROUP BY ALL, x and GROUP BY ROLLUP(x), ALL; probed on 1.5.4), so the branch consumes
exactly the one keyword. When off, ALL after GROUP BY falls through to
the expression grammar, where every shipped dialect reserves it — a clean
parse error. A separate flag from order_by_all,
not one paired gate: the paired-flag doctrine (the straight_join /
table_options precedent) covers grammar points a dialect only ever ships
together, but these are two independent constructs on two clauses that real
engines adopt separately (Snowflake ships GROUP BY ALL with no
ORDER BY ALL), so pairing them would bake a DuckDB coincidence into the
vocabulary. On for DuckDB / Lenient, off elsewhere.
group_by_set_quantifier: boolAccept PostgreSQL’s GROUP BY {DISTINCT | ALL} <grouping items> set-quantifier
(SQL:2016 feature T434): a DISTINCT/ALL prefix on the whole grouping clause
that governs deduplication of the generated grouping sets
(Select::group_by_quantifier). The quantifier requires a
non-empty grouping list — PostgreSQL rejects a bare GROUP BY ALL /
GROUP BY DISTINCT (probed on pg_query PG-17) — which is what keeps it MECE with
group_by_all, DuckDB’s mode where ALL is the entire
clause. A separate flag from group_by_all for that reason: the two constructs
spell an overlapping keyword (ALL) but mean opposite things (a modifier on a
list vs. a standalone mode), and no shipped dialect but Lenient enables both.
Under Lenient (both on) the forms stay disambiguated by lookahead — a bare
GROUP BY ALL is the DuckDB mode, GROUP BY ALL <items> is the PostgreSQL
quantifier — so the widening is conflict-free. When off, the DISTINCT/ALL
keyword after GROUP BY falls through to the grouping-item grammar, where every
shipped dialect reserves it — a clean parse error. On for PostgreSQL / Lenient,
off elsewhere.
order_by_all: boolAccept DuckDB’s ORDER BY ALL [ASC | DESC] [NULLS FIRST | LAST] clause
mode: sort by every projection column, left to right
(Query::order_by_all — a mode of the whole clause,
never a sort-key expression). ALL cannot mix with explicit keys
(ORDER BY ALL, x / ORDER BY x, ALL syntax-error; probed on 1.5.4) and
takes no USING tail. The gate covers only the query-level clause, the
one position DuckDB gives mode semantics: window ORDER BY ALL is a
dedicated DuckDB parse error (“Cannot ORDER BY ALL in a window
expression”), and the aggregate-internal agg(x ORDER BY ALL) form —
which DuckDB reads as a COLUMNS(*) star expansion producing one output
per column — is a different grammar position: a sort key
(Expr::Columns), gated with the node’s own
CallSyntax::columns_expression.
When off, ALL after ORDER BY falls through to
the expression grammar, where every shipped dialect reserves it — a clean
parse error. On for DuckDB / Lenient, off elsewhere; see
group_by_all for why the two are separate flags.
Implementations§
Source§impl GroupingSyntax
impl GroupingSyntax
Sourcepub const CLICKHOUSE: Self
Available on crate feature clickhouse only.
pub const CLICKHOUSE: Self
clickhouse only.The CLICKHOUSE preset for grouping syntax.
Source§impl GroupingSyntax
impl GroupingSyntax
Sourcepub const DATABRICKS: Self
Available on crate feature databricks only.
pub const DATABRICKS: Self
databricks only.The DATABRICKS preset for grouping syntax.
Trait Implementations§
Source§impl Clone for GroupingSyntax
impl Clone for GroupingSyntax
Source§fn clone(&self) -> GroupingSyntax
fn clone(&self) -> GroupingSyntax
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more