pub enum TableConstraint<X: Extension = NoExt> {
PrimaryKey {
columns: ThinVec<IndexColumn<X>>,
include: ThinVec<Ident>,
meta: Meta,
},
Unique {
columns: ThinVec<IndexColumn<X>>,
nulls_not_distinct: Option<bool>,
include: ThinVec<Ident>,
meta: Meta,
},
Check {
expr: Box<Expr<X>>,
meta: Meta,
},
Exclude {
exclude: Box<ExcludeConstraint<X>>,
meta: Meta,
},
ForeignKey {
columns: ThinVec<Ident>,
references: Box<ForeignKeyRef>,
meta: Meta,
},
Bare {
meta: Meta,
},
Other {
ext: X,
meta: Meta,
},
}Expand description
The SQL table constraint forms represented by the AST.
Variants§
PrimaryKey
A PRIMARY KEY (col, …) table constraint.
Fields
columns: ThinVec<IndexColumn<X>>The key columns. Each is an IndexColumn — the same “indexed-column” shape
CreateIndex uses — so a column may carry a COLLATE <collation> postfix
(folded into IndexColumn::expr as an Expr::Collate) and an
ASC/DESC sort order. The bare-column case is an
Expr::Column with asc/nulls_first unset — the shape every
dialect produces. The COLLATE/ordering decoration is gated for acceptance by
ConstraintSyntax::constraint_column_collate_order
(SQLite): off elsewhere, where a bare name is the only accepted form and a
trailing COLLATE/ASC/DESC is a clean parse error. SQLite prohibits general
expressions and NULLS FIRST/LAST in this position, so the parser never fills
nulls_first nor produces a non-column/non-collate expr here.
include: ThinVec<Ident>The INCLUDE (<col>, ...) covering-index columns (PostgreSQL): non-key payload
columns stored in the primary key’s implicit index (PRIMARY KEY (a) INCLUDE (b)).
Empty when no INCLUDE clause is written. Gated for acceptance by
ConstraintSyntax::index_constraint_parameters;
off elsewhere, where INCLUDE after the key list is a clean parse error.
Unique
A UNIQUE (col, …) table constraint.
Fields
columns: ThinVec<IndexColumn<X>>The key columns, as on PrimaryKey: IndexColumns
admitting a per-column COLLATE <collation> and ASC/DESC under the same
ConstraintSyntax::constraint_column_collate_order
gate.
nulls_not_distinct: Option<bool>The NULLS [NOT] DISTINCT null-treatment (PostgreSQL 15+), as on the column-level
ColumnOption::Unique. Some(false) = NULLS NOT DISTINCT, Some(true) = the
explicit NULLS DISTINCT default, None = unwritten. Gated for acceptance by
ConstraintSyntax::index_constraint_parameters.
include: ThinVec<Ident>The INCLUDE (<col>, ...) covering-index columns (PostgreSQL), as on
PrimaryKey. Empty when unwritten. Same gate.
Check
A CHECK (<predicate>) table constraint.
Fields
Exclude
A PostgreSQL EXCLUDE [USING <method>] (<element> WITH <operator> [, ...]) [INCLUDE (...)] [WITH (...)] [USING INDEX TABLESPACE ...] [WHERE (...)] exclusion constraint —
no two rows may hold values that all pairwise satisfy the named operators. The whole
clause is boxed into ExcludeConstraint so this cold, rarely-written variant does not
widen the warm TableConstraint enum (the box/inline budget — the same reason
ForeignKey boxes its ForeignKeyRef). Gated for acceptance by
ConstraintSyntax::exclusion_constraints; off
elsewhere (DuckDB included, which rejects it), where EXCLUDE at a constraint position is
a clean parse error.
Fields
exclude: Box<ExcludeConstraint<X>>The exclusion-constraint specification; see ExcludeConstraint.
ForeignKey
A FOREIGN KEY (col, …) REFERENCES … table constraint.
Fields
references: Box<ForeignKeyRef>The foreign-key target table, columns, and options; see ForeignKeyRef.
Bare
A trailing bodyless CONSTRAINT <name> (SQLite), standalone in the table-element list
(CREATE TABLE t (a INT, CONSTRAINT cn)) — the TableConstraintDef::name is written
but no constraint element follows it. SQLite also lets the comma separating this from a
preceding table constraint be omitted (UNIQUE(a) CONSTRAINT cn, engine-measured
accepted); the parser’s table-element loop handles that comma elision, not this variant.
Gated for acceptance by
ConstraintSyntax::bare_constraint_name; off
elsewhere, where a CONSTRAINT <name> with nothing following is a clean parse error.
Other
Dialect extension node supplied by the extension type.
Trait Implementations§
Source§impl<X: Clone + Extension> Clone for TableConstraint<X>
impl<X: Clone + Extension> Clone for TableConstraint<X>
Source§fn clone(&self) -> TableConstraint<X>
fn clone(&self) -> TableConstraint<X>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<'de, X> Deserialize<'de> for TableConstraint<X>where
X: Deserialize<'de> + Extension,
impl<'de, X> Deserialize<'de> for TableConstraint<X>where
X: Deserialize<'de> + Extension,
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl<X: Eq + Extension> Eq for TableConstraint<X>
Source§impl<X: Extension + Render> Render for TableConstraint<X>
impl<X: Extension + Render> Render for TableConstraint<X>
Source§fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
fn render(&self, ctx: &RenderCtx<'_>, f: &mut Formatter<'_>) -> Result
Source§fn operand_binding_power(&self) -> Option<BindingPower>
fn operand_binding_power(&self) -> Option<BindingPower>
None (the default) for a self-delimiting node — an atom, call, or
constructor — that never needs parentheses. Read moreSource§impl<X> Serialize for TableConstraint<X>
impl<X> Serialize for TableConstraint<X>
Source§impl<X: Extension> Spanned for TableConstraint<X>
impl<X: Extension> Spanned for TableConstraint<X>
impl<X: PartialEq + Extension> StructuralPartialEq for TableConstraint<X>
Auto Trait Implementations§
impl<X> Freeze for TableConstraint<X>where
X: Freeze,
impl<X> RefUnwindSafe for TableConstraint<X>where
X: RefUnwindSafe,
impl<X> Send for TableConstraint<X>where
X: Send,
impl<X> Sync for TableConstraint<X>where
X: Sync,
impl<X> Unpin for TableConstraint<X>where
X: Unpin,
impl<X> UnsafeUnpin for TableConstraint<X>where
X: UnsafeUnpin,
impl<X> UnwindSafe for TableConstraint<X>where
X: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynAstExt for T
impl<T> DynAstExt for T
Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&dyn Any for downcasting a node back to its concrete type.Source§fn dyn_clone(&self) -> Box<dyn DynAstExt>
fn dyn_clone(&self) -> Box<dyn DynAstExt>
Clone (whose
Self-returning signature cannot go through a vtable).Source§fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
fn dyn_eq(&self, other: &dyn DynAstExt) -> bool
PartialEq (whose &Self argument cannot go through a vtable). Equal
iff other holds the same concrete type and that type deems the values
equal; differently-typed nodes are never equal.