pub enum TableConstraint {
PrimaryKey {
columns: Vec<IndexedColumn>,
on_conflict: Option<ConflictAction>,
autoincrement: bool,
},
Unique {
columns: Vec<IndexedColumn>,
on_conflict: Option<ConflictAction>,
},
Check {
expr: ExprId,
on_conflict: Option<ConflictAction>,
},
ForeignKey {
columns: Vec<NameId>,
clause: ForeignKeyClause,
},
}Expand description
A table-level constraint.
Variants§
PrimaryKey
PRIMARY KEY (...).
Fields
columns: Vec<IndexedColumn>The key columns.
on_conflict: Option<ConflictAction>The conflict clause.
Unique
UNIQUE (...).
Fields
columns: Vec<IndexedColumn>The key columns.
on_conflict: Option<ConflictAction>The conflict clause.
Check
CHECK (expr) [conflict].
Parsed and then ignored, which is what SQLite does with it.
tcons ::= CHECK LP expr RP onconf accepts the clause and
sqlite3AddCheckConstraint never reads it, so
CONSTRAINT small CHECK(b < 9) ON CONFLICT FAIL behaves exactly as
ABORT: measured against the pinned 3.53.4, an INSERT of three rows
whose second fails keeps none of them.
It is in the tree rather than discarded at the token because the table’s
CREATE text is stored and re-parsed on every open, so the grammar has
to accept everything the text can hold. Not accepting it did not cost
one statement a clause - it made the CREATE TABLE a parse error, and
every statement after it said no such table.
Fields
on_conflict: Option<ConflictAction>The conflict clause, accepted and not acted on.
ForeignKey
FOREIGN KEY (...) REFERENCES ....