Skip to main content

TableConstraint

Enum TableConstraint 

Source
pub enum TableConstraint {
    PrimaryKey {
        name: Option<String>,
        columns: Vec<String>,
        deferrable: bool,
        initially_deferred: bool,
    },
    Unique {
        name: Option<String>,
        columns: Vec<String>,
        nulls_not_distinct: bool,
        deferrable: bool,
        initially_deferred: bool,
        prefix_lengths: Vec<Option<u32>>,
    },
    Check {
        name: Option<String>,
        expr: Expr,
        not_valid: bool,
    },
    Exclude {
        name: Option<String>,
        method: Option<String>,
        elements: Vec<(String, String)>,
    },
    Index {
        name: Option<String>,
        columns: Vec<String>,
        prefix_lengths: Vec<Option<u32>>,
    },
    FulltextIndex {
        name: Option<String>,
        columns: Vec<String>,
    },
}
Expand description

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).

Variants§

§

PrimaryKey

PRIMARY KEY (col1, col2, ...). Implies NOT NULL on each referenced column. Engine builds a BTree index named <table>_pkey and enforces composite uniqueness on INSERT.

Fields

§columns: Vec<String>
§deferrable: bool

v7.39 (round 711) — [NOT] DEFERRABLE [INITIALLY DEFERRED]. Round 621 consumed the clauses; these carry them.

§initially_deferred: bool
§

Unique

UNIQUE (col1, col2, ...). Engine builds a BTree index named <table>_<leading_col>_key (single-column) or <table>_<leading_col>_<…>_key (composite) and enforces uniqueness on INSERT.

Fields

§columns: Vec<String>
§nulls_not_distinct: bool

v7.13.0 — NULLS NOT DISTINCT modifier (mailrs round-5 G10). PG 15+ flips the NULL handling so any number of NULL rows collide on the constraint. Default is false (NULLS DISTINCT, standard SQL behaviour).

§deferrable: bool

v7.39 (round 711) — see PrimaryKey.

§initially_deferred: bool
§prefix_lengths: Vec<Option<u32>>

v7.40.0 — MySQL’s per-column index prefix on a UNIQUE KEY k (b(4)), aligned with columns. Unlike a plain KEY’s, this one CHANGES what the constraint accepts: MySQL rejects two rows sharing the first four characters. Empty for every PostgreSQL spelling.

§

Check

v7.13.0 — CHECK (<expr>) table-level constraint (mailrs round-5 G3). Column-level inline CHECKs fold into this same variant at parse time. Engine evaluates the predicate against each INSERT/UPDATE candidate row; a false / NULL result rejects the mutation. v7.39 (round 652) — not_valid carries the NOT VALID suffix. PG adds such a constraint without scanning the existing rows: new rows are checked, the ones already there are grandfathered in, and pg_constraint.convalidated reads f until VALIDATE CONSTRAINT scans and flips it. pg_dump emits the suffix for exactly those, so validating them on restore would refuse a dump PG itself produced.

Fields

§expr: Expr
§not_valid: bool
§

Exclude

v7.39 (round 210) — EXCLUDE [USING <method>] (<col> WITH <op> [, …]): no two rows may satisfy (r.c1 op1 s.c1) AND … for every element (the booking/scheduling non-overlap constraint, EXCLUDE USING gist (during WITH &&)). method is the index AM name (gist/spgist/btree — informational in Phase 0; the O(n) enforcement doesn’t build the index yet). Each element pairs a column name with an operator spelling (&&, =, @>, …).

Fields

§method: Option<String>
§elements: Vec<(String, String)>
§

Index

v7.15.0 — MySQL KEY name (cols) / INDEX name (cols) non-unique secondary-index declaration inline in CREATE TABLE. Engine builds a BTree index on the leading column (composite columns parse but only the leading column is honoured at v7.15 — matches the existing CreateIndexStatement::extra_columns semantics). Useful for mysql/blog-style schemas that lean on routine secondary indexes for ORM lookups.

Fields

§columns: Vec<String>
§prefix_lengths: Vec<Option<u32>>

v7.40.0 — MySQL’s per-column index prefix, KEY k (b(4)), positionally aligned with columns. None for a column written without one, which is every PostgreSQL index key.

It was skipped by the parser and dropped, so the declaration was accepted and the index built over the whole column with nothing recording that a prefix had been asked for — SHOW INDEX then reported Sub_part NULL and SHOW CREATE TABLE printed (b) where MySQL 9.7.2 prints (b(4)).

§

FulltextIndex

v7.17.0 Phase 2.2 — MySQL FULLTEXT KEY/INDEX [name] (cols) inline declaration. Pre-v7.17 the parser silently dropped these so MyISAM-imported FULLTEXT indexes vanished; v7.17 routes them through the existing tsvector-GIN engine path so MATCH AGAINST queries get a real inverted index instead of falling back to a full scan. Multi-column FULLTEXT KEYs build one GIN per column at v7.17 (per-column posting lists); the leading column drives query planning.

Fields

§columns: Vec<String>

Trait Implementations§

Source§

impl Clone for TableConstraint

Source§

fn clone(&self) -> TableConstraint

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 Debug for TableConstraint

Source§

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

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

impl Display for TableConstraint

Source§

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

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

impl PartialEq for TableConstraint

Source§

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

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.