diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2021-12-08 11:09:44 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2021-12-08 11:13:57 +0100 |
commit | d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a (patch) | |
tree | 621d033b72ab7da8a21acb729b41c015b6322747 /src/include/catalog/pg_constraint.h | |
parent | e464cb7af317e216fef9bfe19a7c4df542817012 (diff) |
Allow specifying column list for foreign key ON DELETE SET actions
Extend the foreign key ON DELETE actions SET NULL and SET DEFAULT by
allowing the specification of a column list, like
CREATE TABLE posts (
...
FOREIGN KEY (tenant_id, author_id) REFERENCES users ON DELETE SET NULL (author_id)
);
If a column list is specified, only those columns are set to
null/default, instead of all the columns in the foreign-key
constraint.
This is useful for multitenant or sharded schemas, where the tenant or
shard ID is included in the primary key of all tables but shouldn't be
set to null.
Author: Paul Martinez <paulmtz@google.com>
Discussion: https://www.postgresql.org/message-id/flat/CACqFVBZQyMYJV=njbSMxf+rbDHpx=W=B7AEaMKn8dWn9OZJY7w@mail.gmail.com
Diffstat (limited to 'src/include/catalog/pg_constraint.h')
-rw-r--r-- | src/include/catalog/pg_constraint.h | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/src/include/catalog/pg_constraint.h b/src/include/catalog/pg_constraint.h index e75baa8e1ed..eab50053b01 100644 --- a/src/include/catalog/pg_constraint.h +++ b/src/include/catalog/pg_constraint.h @@ -139,6 +139,12 @@ CATALOG(pg_constraint,2606,ConstraintRelationId) Oid conffeqop[1] BKI_LOOKUP(pg_operator); /* + * If a foreign key with an ON DELETE SET NULL/DEFAULT action, the subset + * of conkey to updated. If null, all columns are updated. + */ + int16 confdelsetcols[1]; + + /* * If an exclusion constraint, the OIDs of the exclusion operators for * each column of the constraint */ @@ -220,6 +226,8 @@ extern Oid CreateConstraintEntry(const char *constraintName, int foreignNKeys, char foreignUpdateType, char foreignDeleteType, + const int16 *fkDeleteSetCols, + int numFkDeleteSetCols, char foreignMatchType, const Oid *exclOp, Node *conExpr, @@ -254,7 +262,8 @@ extern Bitmapset *get_primary_key_attnos(Oid relid, bool deferrableOk, Oid *constraintOid); extern void DeconstructFkConstraintRow(HeapTuple tuple, int *numfks, AttrNumber *conkey, AttrNumber *confkey, - Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs); + Oid *pf_eq_oprs, Oid *pp_eq_oprs, Oid *ff_eq_oprs, + int *num_fk_del_set_cols, AttrNumber *fk_del_set_cols); extern bool check_functional_grouping(Oid relid, Index varno, Index varlevelsup, |