pub struct ConstraintSyntax {
pub deferrable_constraints: bool,
pub named_inline_non_check_constraints: bool,
pub bare_constraint_name: bool,
pub exclusion_constraints: bool,
pub constraint_no_inherit_not_valid: bool,
pub index_constraint_parameters: bool,
pub constraint_column_collate_order: bool,
pub referential_action_cascade_set: bool,
pub check_constraint_subqueries: bool,
}Expand description
Dialect-owned table/column-constraint syntax accepted by the parser.
The constraint forms and their decorations. Split out of the retired
SchemaChangeSyntax at its 16-field line as the constraint axis, distinct from the
table-clause and column-definition axes. Each flag is a grammar gate: when off the
constraint keyword is left unconsumed and rejects.
Fields§
§deferrable_constraints: boolAccept a trailing <constraint characteristics> clause ([NOT] DEFERRABLE,
INITIALLY {DEFERRED | IMMEDIATE}) on a table/column constraint, in both CREATE TABLE and ALTER TABLE ADD CONSTRAINT. On for PostgreSQL/SQLite/DuckDB/Lenient.
MySQL has no deferrable constraints — … REFERENCES t (c) DEFERRABLE / INITIALLY DEFERRED are ER_PARSE_ERROR on mysql:8 — so it is off there and the
DEFERRABLE/INITIALLY keyword surfaces as a clean parse error.
named_inline_non_check_constraints: boolAccept a CONSTRAINT <symbol> name prefix on a non-CHECK inline column constraint
(a INT CONSTRAINT c REFERENCES b, … CONSTRAINT c UNIQUE). On for ANSI/PostgreSQL/
SQLite/DuckDB/Lenient. MySQL admits a named inline constraint only for CHECK
(a INT CONSTRAINT c CHECK (…) parses on mysql:8), so a CONSTRAINT <symbol> before
any other inline column constraint — REFERENCES, UNIQUE, PRIMARY KEY,
NOT NULL — is an ER_PARSE_ERROR; it is off there. The bare, unnamed inline
constraints and the named CHECK are unaffected either way.
bare_constraint_name: boolAccept a trailing bodyless CONSTRAINT <name> — a nameable constraint marker with no
constraint element after it — in a column definition (a INT CONSTRAINT cn) or as a
standalone table constraint (CREATE TABLE t (a INT, CONSTRAINT cn)), recorded as
ColumnOption::Bare/TableConstraint::Bare.
SQLite’s grammar makes the constraint element optional after CONSTRAINT <name>, and (in
the table-constraint list only) lets the separating comma before such a bare marker be
omitted too — UNIQUE(a) CONSTRAINT c and CONSTRAINT a UNIQUE(x) CONSTRAINT b both
engine-measured accept, any number of bare/named-with-body constraints chaining freely.
Parsed only when nothing but the element terminator (,/)) follows the name — a
CONSTRAINT <name> immediately followed by a constraint element (CHECK, UNIQUE, …)
still takes that element as its body, unaffected by this flag. On for SQLite/Lenient. Off
elsewhere (PostgreSQL engine-measured rejects a bodyless CONSTRAINT <name>, requiring a
constraint element), where a CONSTRAINT <name> with nothing following is a clean parse
error.
exclusion_constraints: boolAccept the PostgreSQL EXCLUDE [USING <method>] (<element> WITH <operator> [, ...]) [tail]
exclusion constraint as a table element (CREATE TABLE t (c circle, EXCLUDE USING gist (c WITH &&))). On for PostgreSQL/Lenient. Off for ANSI/MySQL/SQLite/DuckDB (DuckDB, which
otherwise inherits the PostgreSQL schema surface, rejects it), where EXCLUDE at a
constraint position is left unconsumed and surfaces as a clean parse error.
constraint_no_inherit_not_valid: boolAccept the NO INHERIT / NOT VALID constraint markers on CHECK (and NOT VALID on
FOREIGN KEY) constraints — PostgreSQL’s shared ConstraintAttributeSpec slot, also
accepted by DuckDB. On for PostgreSQL/DuckDB/Lenient. Off for ANSI/MySQL/SQLite, where the
NO INHERIT / NOT VALID keywords after a constraint are left unconsumed and surface as a
clean parse error. The parser enforces which constraint kinds admit which marker
(PostgreSQL rejects NOT VALID on PRIMARY KEY/UNIQUE/EXCLUDE and NO INHERIT on
everything but CHECK, in the grammar action — reproduced at parse), so the flag only
opens the keywords, not every combination.
index_constraint_parameters: boolAccept the PostgreSQL index-backed-constraint parameters on UNIQUE/PRIMARY KEY: the
covering INCLUDE (<col>, ...) list, the NULLS [NOT] DISTINCT null-treatment (PG 15+),
and the USING INDEX TABLESPACE <name> index tablespace. The three travel together as one
PostgreSQL ConstraintElem index-parameter unit (the same “single dialect unit” rationale
as column_storage). On for PostgreSQL/Lenient. Off for
ANSI/MySQL/SQLite/DuckDB (DuckDB rejects all three), where the INCLUDE/NULLS/USING
keyword is left unconsumed and surfaces as a clean parse error.
constraint_column_collate_order: boolAccept a per-column COLLATE <collation> and ASC/DESC sort order inside a
PRIMARY KEY (...) / UNIQUE (...) table-constraint column list — SQLite’s
“indexed-column” spelling in constraint position (PRIMARY KEY (a COLLATE nocase),
UNIQUE ('b' COLLATE nocase DESC)). On for SQLite/Lenient.
Engine-measured scope (constraint position, not CREATE INDEX): SQLite admits a bare
column name optionally decorated with COLLATE/ASC/DESC, but prohibits general
expressions (UNIQUE (a+b) / (lower(a)) → “expressions prohibited in PRIMARY KEY and
UNIQUE constraints”) and NULLS FIRST/LAST (“unsupported use of NULLS FIRST”), so the
widened parser stays column-name + COLLATE + ASC/DESC and never fills
IndexColumn::nulls_first. Off for ANSI/PostgreSQL/DuckDB
(all engine-measured reject COLLATE/ASC/DESC here — the decoration belongs to their
CREATE INDEX grammar, not the table constraint), where the keyword is left unconsumed
and surfaces as a clean parse error. Also off for MySQL: its key_part admits ASC/DESC
and length prefixes / functional (expr) parts but not COLLATE, a differently-shaped
surface with no corpus demand — left off and scoped out rather than modelled as this
SQLite-shaped gate.
referential_action_cascade_set: boolAccept the cascading referential actions ON {DELETE|UPDATE} {CASCADE | SET NULL | SET DEFAULT} on a foreign-key constraint. On for ANSI/PostgreSQL/MySQL/SQLite/Lenient.
DuckDB parse-rejects those three actions (“FOREIGN KEY constraints cannot use CASCADE,
SET NULL or SET DEFAULT”, probed on 1.5.4) while still admitting RESTRICT and
NO ACTION, so it is off there; with the flag off those three keywords after
ON DELETE/ON UPDATE surface as a clean parse error. Distinct from admitting the
ON DELETE/ON UPDATE clause itself — RESTRICT/NO ACTION remain free either way.
check_constraint_subqueries: boolAccept a subquery (or EXISTS / IN (SELECT …)) inside a CHECK constraint
expression. On for ANSI/PostgreSQL/MySQL/Lenient. Off for SQLite and DuckDB, both of
which parse-reject subqueries in CHECK (“subqueries prohibited in CHECK constraints”,
engine-measured); with the flag off a subquery in the CHECK body is a clean parse error.
Implementations§
Trait Implementations§
Source§impl Clone for ConstraintSyntax
impl Clone for ConstraintSyntax
Source§fn clone(&self) -> ConstraintSyntax
fn clone(&self) -> ConstraintSyntax
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more