Skip to main content

GroupingSyntax

Struct GroupingSyntax 

Source
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: bool

Accept 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: bool

Accept 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: bool

Accept 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: bool

Accept 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: bool

Accept 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: bool

Accept 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

Source

pub const ANSI: Self

The ANSI predefined value.

Source§

impl GroupingSyntax

Source

pub const CLICKHOUSE: Self

Available on crate feature clickhouse only.

The CLICKHOUSE preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const DATABRICKS: Self

Available on crate feature databricks only.

The DATABRICKS preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const DUCKDB: Self

Available on crate feature duckdb only.

The DUCKDB preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const LENIENT: Self

Available on crate feature lenient only.

The LENIENT preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const MYSQL: Self

Available on crate feature mysql only.

The MYSQL preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const POSTGRES: Self

Available on crate feature postgres only.

The POSTGRES preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const SNOWFLAKE: Self

Available on crate feature snowflake only.

The SNOWFLAKE preset for grouping syntax.

Source§

impl GroupingSyntax

Source

pub const SQLITE: Self

Available on crate feature sqlite only.

The SQLITE preset for grouping syntax.

Trait Implementations§

Source§

impl Clone for GroupingSyntax

Source§

fn clone(&self) -> GroupingSyntax

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for GroupingSyntax

Source§

impl Debug for GroupingSyntax

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for GroupingSyntax

Source§

impl PartialEq for GroupingSyntax

Source§

fn eq(&self, other: &GroupingSyntax) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for GroupingSyntax

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.