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
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
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.
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 (&&, =, @>, …).
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
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.
Trait Implementations§
Source§impl Clone for TableConstraint
impl Clone for TableConstraint
Source§fn clone(&self) -> TableConstraint
fn clone(&self) -> TableConstraint
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more