Skip to main content

ConstraintSyntax

Struct ConstraintSyntax 

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

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

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

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

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

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

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

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

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

Accept 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§

Source§

impl ConstraintSyntax

Source

pub const ANSI: Self

The ANSI predefined value.

Source§

impl ConstraintSyntax

Source

pub const LENIENT: Self

Available on crate feature lenient only.

The LENIENT preset for constraint syntax.

Source§

impl ConstraintSyntax

Source

pub const MYSQL: Self

Available on crate feature mysql only.

The MYSQL preset for constraint syntax.

Source§

impl ConstraintSyntax

Source

pub const POSTGRES: Self

Available on crate feature postgres only.

The POSTGRES preset for constraint syntax.

Source§

impl ConstraintSyntax

Source

pub const SQLITE: Self

Available on crate feature sqlite only.

The SQLITE preset for constraint syntax.

Trait Implementations§

Source§

impl Clone for ConstraintSyntax

Source§

fn clone(&self) -> ConstraintSyntax

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 ConstraintSyntax

Source§

impl Debug for ConstraintSyntax

Source§

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

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

impl Eq for ConstraintSyntax

Source§

impl PartialEq for ConstraintSyntax

Source§

fn eq(&self, other: &ConstraintSyntax) -> 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 ConstraintSyntax

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.