Expand description
AST for the PG-dialect subset SPG accepts in v0.2.
Display is implemented so that for any AST a produced by crate::parser,
re-parsing format!("{a}") yields a structurally equal AST. Binary and
unary operators always emit parentheses to remove any precedence
ambiguity — round-trip safety wins over prettiness.
Structs§
- Alter
Index Statement - Alter
Policy Statement - v7.39 (RLS) —
ALTER POLICY name ON table { RENAME TO new | [TO roles] [USING (expr)] [WITH CHECK (expr)] }. Cannot change PERMISSIVE/RESTRICTIVE or the command (matches PG). - Alter
Sequence Statement - v7.17.0 —
ALTER SEQUENCEAST node. - Alter
Table Statement - v6.7.2 —
ALTER TABLE t SET <setting> = <value>. v6.7.2 ships the singlehot_tier_bytessetting; later v6.7.x sub-versions can add more SET subjects without changing the dispatch shape. - Column
Def - Column
Name - Copy
Options - Options for
COPY … TO STDOUT [WITH] (…). Defaults reproduce the bareCOPY … TO STDOUTtext-format behaviour, so an empty option list is a no-op.delimiter/null_str/quotefall back to the per-format defaults (text:\t/\N; csv:,/ `` /") when unset. - Create
Domain Statement - v7.17.0 Phase 1.5 —
CREATE DOMAINAST. - Create
Function Statement - v7.12.4 —
CREATE [OR REPLACE] FUNCTION. v7.12.4 shipsRETURNS TRIGGER LANGUAGE plpgsqlas the primary use case (the row-level trigger body the CREATE TRIGGER below references). Non-trigger user-defined functions parse but error at execution time with a clear unsupported message; that surface lands in v7.12.5+. - Create
Index Statement - Create
Materialized View Statement - v7.17.0 Phase 1.3 —
CREATE MATERIALIZED VIEWAST node. - Create
Policy Statement - v7.39 (RLS) —
CREATE POLICY name ON table [AS {PERMISSIVE|RESTRICTIVE}] [FOR cmd] [TO roles] [USING (expr)] [WITH CHECK (expr)]. - Create
Publication Statement - v6.1.2 —
CREATE PUBLICATIONAST node. Thescopefield uses thePublicationScopeshape. v6.1.2 only acceptedAllTables; v6.1.3 unlocks theForTables/AllTablesExceptvariants by flipping the parser gate (no AST migration). - Create
Rule Statement - v7.39 (round 139) —
CREATE RULEquery-rewrite rule AST node. - Create
Sequence Statement - v7.17.0 —
CREATE SEQUENCEAST node. SeeStatement::CreateSequence. - Create
Subscription Statement - v6.1.4 —
CREATE SUBSCRIPTIONAST node. v6.1.4 ships a single fixed-shape DDL; the WITH-clause options PG supports (enabled,slot_name,streaming,binary) are out of scope for v6.1.4 —enableddefaults to true and there are no other knobs to set in v6.1.x. - Create
Table Statement - Create
Trigger Statement - v7.12.4 —
CREATE [OR REPLACE] TRIGGER. Always row-level (FOR EACH ROW) in v7.12.4 — statement-level triggers parse but the executor refuses them.WHEN (cond)clauses are out of scope; the trigger function can short-circuit on a leading IF inside its body once v7.12.5 lands IF. - Create
Type Statement - v7.17.0 Phase 1.4 —
CREATE TYPEAST. - Create
User Statement - Create
View Statement - v7.17.0 Phase 1.2 —
CREATE VIEWAST node. - Cte
- Cycle
Clause - v7.38 (read01 U16) — parsed
CYCLE … SET … [TO … DEFAULT …] USING …. - Delete
Statement DELETE FROM <table> [WHERE cond]. v4.4 — removes matched rows from the active catalog and prunes them from every index.- DmlOrder
Limit UPDATE <table> SET col = expr [, ...] [WHERE cond]. v4.4 — the engine evaluatesexprper matched row in the table’s row order and rewrites cells in place. Indexed columns are dropped + re- inserted into the affected B-tree on each row change. v7.39 (round 413) — the boxed payload for MySQL’sORDER BY [LIMIT]tail on a DML statement. Boxed off the statement struct so the PG-only common path stays at its pre-r413 size (see the round-305 nesting-stack lesson). v7.39 (round 431+1) — DELETE carries the identical clause with the identical meaning, so both share this one payload rather than each growing its own.- Drop
Policy Statement - v7.39 (RLS) —
DROP POLICY [IF EXISTS] name ON table. - Exception
Handler - v7.37.20 (20.10) — one
WHEN <cond> [OR <cond>...] THEN <body>arm inside an EXCEPTION block. - Explain
Statement - Each bool mirrors one independent PG
EXPLAIN (…)option (ANALYZE, SUGGEST, COSTS OFF, BUFFERS, TIMING OFF, …); they compose freely, so a bitflags word or a nested options struct would only relocate the lint while making the option each caller sets harder to read. - Foreign
KeyConstraint - v7.6.0 — A single FOREIGN KEY constraint. Both column-level
REFERENCESand table-levelFOREIGN KEY (...) REFERENCES ...parse into this shape — the column-level form has a single-entrycolumns/parent_columns. - From
Clause - FROM clause shape. v1.10 accepts a primary table plus a flat list of
joined peers —
FROM a [, b]* [INNER|LEFT] JOIN c ON expr .... The joins evaluate left-associatively in nested-loop order. - From
Join - Function
Arg - v7.12.4 — one positional argument to a
CREATE FUNCTION. - Function
Attrs - v7.39 (round 322, V46) — the attribute clauses
CREATE FUNCTIONaccepts on either side of its body. Defaults are PG’s: VOLATILE, called on null input, SECURITY INVOKER, not leakproof, PARALLEL UNSAFE, and the language’s default cost / rows. - Grant
Priv - v7.39 (read01 round 59) — one privilege in a GRANT, with the optional COLUMN
list PG allows per privilege:
GRANT SELECT (a, b), INSERT (c) ON t TO dan. An empty column list means the privilege is table-wide. - Grant
Statement - v7.39 (read01 round 57) — a parsed GRANT / REVOKE. The same shape serves
both;
Statement::GrantvsStatement::Revokesays which way it runs. - Index
Column Order - v7.39 (round 537) — a
CREATE INDEXkey column’s ordering clause. - Insert
Statement - Json
Table - v7.39 (round 205) — a
JSON_TABLEFROM item. - Like
Options - Which properties
LIKEcarries over. A bareLIKEcopies names, types and NOT NULL and nothing else — measured on PG18, where a copied generated column becomes a plain one and a copied identity column loses its identity. - Like
Spec - v7.39 (round 531) —
LIKE <table> [ {INCLUDING|EXCLUDING} <opt> ]*inside a CREATE TABLE column list. - Locking
Clause - v7.39 (round 293, E3 Phase 1) — a row-locking clause.
- Merge
Statement - v7.17.0 Phase 3.P0-42 — SQL:2003 / PG 15+ MERGE statement.
One WHEN clause fires per source row depending on whether the
oncondition matched any target row(s); the executor walksclausesin declaration order and fires the first whosematchedkind and optionalconditionare both satisfied. - Merge
When Clause - OnConflict
Clause - v7.9.7 — INSERT upsert clause:
ON CONFLICT (target) DO action. - OrderBy
- Partition
BySpec - v7.37.6-B —
PARTITION BY <kind> (key_columns…)parent suffix. v7.37.6-B only RANGE is recognised; the enum keeps space for future LIST / HASH without breaking the public AST shape. - Partition
OfSpec - v7.37.6-B —
PARTITION OF <parent> <bounds>child suffix. Bounds is either a half-open range (FOR VALUES FROM (a) TO (b)) or the catch-allDEFAULTpartition. - PlPg
SqlBlock - v7.12.4 — PL/pgSQL
BEGIN ... END;block. v7.12.6 widens from assignment + return to a real-PL/pgSQL surface:DECLARE-block local variables,IF/ELSIF/ELSE/END IFcontrol flow,RAISEdiagnostics, and embedded SQL statements that execute through the regular engine path. The remaining v7.12.x carve-out is loops (LOOP/WHILE/FOR), which mailrs’s trigger doesn’t need but other PG customers may; deferred to a future minor release. - PlPg
SqlDeclare - v7.12.6 — single
DECLAREentry: variable name + declared type + optional initialiser. Variables default to SQL NULL when no init is given (matches PG). - Search
Clause - v7.38 (read01 U16) — parsed
SEARCH … FIRST BY … SET …clause. - Select
Statement - Sequence
Options - v7.17.0 — option grammar shared by CREATE / ALTER SEQUENCE.
All fields are optional.
min_value/max_valuecarrySome(SeqBound::NoBound)forNO MINVALUE/NO MAXVALUE. - SetDb
Role Setting Statement - v7.39 (round 547) — see
Statement::SetDbRoleSetting. Boxed in the enum so the variant costs one pointer. - Table
Ref - Update
From Sources - v7.39 (round 533) — what
UPDATE … FROM src WHERE condwas lowered FROM, kept so the engine can finish the job. - Update
Statement - Window
Frame - v4.20 explicit window frame:
ROWS|RANGE BETWEEN <bound> AND <bound>.endisNonefor the shorthand “ROWS” where end implicitly = CURRENT ROW.
Enums§
- Alter
Domain Action - v7.39 (round 260) — the
ALTER DOMAINactions SPG implements. - Alter
Index Target - Alter
Table Target - Assign
Target - BinOp
- Cast
Target - Collation
- v7.17.0 Phase 2.5 — text collation classification surfaced
from the SQL parser. Mirrors
spg_storage::Collation; the engine bridges between the two at CREATE TABLE time. - Column
Type Name - SQL-level type names. The mapping to the storage runtime’s
DataTypehappens inspg-engine— keepingspg-sqlfree of storage deps. - Copy
Format COPY … TO STDOUToutput format.textis PG’s default (tab-separated,\Nnulls, backslash escapes);csvfollows RFC-4180-style quoting.- CteBody
- v7.37.43-T4.4 — CTE body. Read-only (Select) or data-modifying (Insert / Update / Delete with optional RETURNING). The data-modifying variants must carry a RETURNING projection for the outer query to reference the CTE alias by; an empty RETURNING is only valid if no outer reference materialises (rare — typically caught at planning).
- Cursor
Direction - v7.39 (round 218) — FETCH / MOVE cursor direction. PG grammar: single-row forms (NEXT / PRIOR / FIRST / LAST / ABSOLUTE n / RELATIVE n) return at most one row; multi-row forms (bare n / ALL / FORWARD [n|ALL] / BACKWARD [n|ALL]) stream a run. A negative bare/FORWARD count means BACKWARD (normalized at execution).
- Discard
Target - v7.39 (round 320, V53) — what a
DISCARDthrows away. - Explain
Format - Expr
- Extract
Field - FkAction
- v7.6.0 — Referential action for
ON DELETE/ON UPDATE. - Frame
Bound - Frame
Exclusion - Frame
Kind - Function
ArgMode - Function
ArgType - Function
Body - Function
Parallel - v7.39 (round 322, V46) — PG’s parallel-safety class.
- Function
Return - Function
Volatility - v7.39 (round 322, V46) — PG’s function volatility class. Declarative:
it tells the planner how far a call may be moved or folded. SPG records
it faithfully (
pg_proc.provolatile,pg_get_functiondef) and does not yet exploit it for constant folding. - Grant
Object - v7.39 (read01 round 57) — the object a GRANT names. SPG enforces TABLE privileges; every other object class parses and is accepted as a no-op, so a pg_dump that grants on schemas / sequences / functions still restores.
- Index
Method - Isolation
Level - v7.38 轴 4 — PG-standard isolation levels. SPG accepts all four
at parse time and tracks the selected value on the engine. The
actual semantic differentiation (REPEATABLE READ snapshot,
SERIALIZABLE SSI) lands in the v7.38 isolation framework train;
today every level reads as effective READ COMMITTED (which is
also how PG treats READ UNCOMMITTED — it silently upgrades to
READ COMMITTED). Default =
ReadCommitted. - Join
Kind - Json
Table Column - v7.39 (round 205) — one entry in a JSON_TABLE (or NESTED) COLUMNS list.
- Json
Table OnBehavior - v7.39 (round 205) — a JSON_TABLE column’s ON EMPTY / ON ERROR clause.
- Limit
Expr - v7.9.24 — LIMIT / OFFSET value. Integer literal at parse
time or a placeholder
$Nresolved during extended-query Bind. mailrs migration follow-up H2. - Literal
- Lock
Strength - PG’s four tuple-lock strengths, weakest first.
- Lock
Wait - What to do when the row is already locked.
- Maintain
Kind - v7.39 (round 535) — which maintenance statement, and therefore what its target names. Measured on PG18: INDEX / TABLE / CLUSTER name a relation, SCHEMA names a schema, and SYSTEM / DATABASE name neither in a way SPG can refuse.
- Match
Type - v7.38 (read01, T29) — FK
MATCHtype. SIMPLE (default) skips the check when ANY referencing column is NULL; FULL requires all-or-none NULL (a mixed-NULL key errors). PARTIAL is parse-rejected (PG does not implement it either). - Merge
Action - Merge
Matched - Mysql
IntWidth - v7.39 (round 386, type-fidelity epic P1) — the declared MySQL narrow
integer width for a column whose
ColumnTypeNameis too wide to carry it:TINYINTcollapses toSmallInt,MEDIUMINTtoInt. Mirrorsspg_storage::MysqlIntWidth; the engine bridges the two at CREATE TABLE time. Only recorded under the MySQL dialect. - Null
Treatment - v6.4.2 — null treatment on
LAG/LEAD/FIRST_VALUE/LAST_VALUE. PG / ANSI default isRespect— NULLs participate in the offset walk.Ignorecauses the function to skip NULL values in the argument expression, returning the next non-NULL. - OnConflict
Action - v7.9.7 — action on conflict.
- Overriding
- v7.38 (read01) —
OVERRIDING { SYSTEM | USER } VALUEon an INSERT. - Partition
Kind Ast - Partition
OfBounds Ast - PlPg
SqlStmt - Policy
Cmd - v7.39 (RLS) — the command a
CREATE POLICYscopes to.Allis the default. - Publication
Scope - v6.1.2 — Which tables a publication covers. v6.1.3 (this commit)
flips the parser gate for the
ForTables/AllTablesExceptvariants — the on-disk shape, snapshot serialisation, and the AST round-trip Display path were already in place in v6.1.2 so this is a parser-only widening. - Raise
Level - Range
Kind Ast - v7.17.0 Phase 3.P0-38 — PG range element kind. Mirrors
spg_storage::RangeKind; we keep it spg-sql-local so the AST crate doesn’t depend on storage. Bridged at engine boundary. - Return
Target - Select
Item - SeqBound
- v7.17.0 —
MINVALUE n/NO MINVALUE. - Sequence
Data Type - v7.17.0 — narrow type for
ASclause of CREATE SEQUENCE. - Sequence
Owned By - v7.17.0 —
OWNED BY {table.col | NONE}. - SetValue
- v7.12.1 — payload of a SET right-hand side. PG syntax accepts
a string literal, an identifier (often a config name), an
integer/float, or the bare
DEFAULTkeyword. - Statement
- Table
Constraint - v7.9.18 — table-level constraint at the end of a CREATE TABLE column list. Either a composite PRIMARY KEY or a UNIQUE (single- or multi-column).
- Trigger
Event - Trigger
ForEach - Trigger
Selector - v7.16.1 — target of
ALTER TABLE … { ENABLE | DISABLE } TRIGGER …. PG also acceptsUSER,REPLICA,ALWAYSmodifiers; v7.16.1 ships the two shapes pg_dump actually emits (ALL+ per-name) — the rest parse-accept asNamedshouldn’t surface from a dump. - Trigger
Timing - Type
Kind - v7.17.0 Phase 1.4 — flavour of the new type. Only ENUM is implemented; the variant set is open so Phase 1.5 (DOMAIN) and later (COMPOSITE, RANGE) can land without an AST shape migration.
- UnOp
- Union
Kind - Validate
Only Kind - v7.39 (round 696) — which operand a
Statement::ValidateOnlynames, and therefore which catalog answers whether it exists. - VecEncoding
- In-cell encoding for a
VECTOR(N)column. v6.0.1 added the optionalUSING <encoding>clause; omitting it keeps the pre-v6F32default.Sq8quantises each cell to a per-vector affine(min, max, [u8; dim])triple (4× compression).F16(v6.0.3, DDL keywordHALF) stores each element as IEEE-754 binary16 (2× compression, ~3 decimal digits of precision). - View
Check Option - v7.39 (read01 round 132) —
WITH [LOCAL | CASCADED] CHECK OPTIONon an auto-updatable view.Cascadedis PG’s default when the bareWITH CHECK OPTIONis written.
Functions§
- figure_
column_ name - v7.39 (round 505) — the column name PG18 gives a projected expression
that carries no
ASalias.Nonemeans?column?. - pretty_
expr - v7.39 (round 311, V32) — PG’s PRETTY deparse of an expression, the
form
pg_get_constraintdef(oid, true)and friends return. - pretty_
expr_ mysql - v7.39 (round 527) — the same deparse, spelling a cast the way MySQL writes it.
- render_
exact_ decimal - Render an exact decimal
unscaled / 10^scale, keeping the scale (trailing zeros):(200, 2)→2.00,(1, 1)→0.1,(-15, 1)→-1.5.