pgsql: Allow specifying column list for foreign key ON DELETE SET actio

From: Peter Eisentraut <peter(at)eisentraut(dot)org>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Allow specifying column list for foreign key ON DELETE SET actio
Date: 2021-12-08 10:27:56
Message-ID: E1muuB2-0004XM-QE@gemulon.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)google(dot)com>
Discussion: https://www.postgresql.org/message-id/flat/CACqFVBZQyMYJV=njbSMxf+rbDHpx=W=B7AEaMKn8dWn9OZJY7w(at)mail(dot)gmail(dot)com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a

Modified Files
--------------
doc/src/sgml/catalogs.sgml | 12 +++
doc/src/sgml/ddl.sgml | 33 +++++++-
doc/src/sgml/ref/alter_table.sgml | 2 +-
doc/src/sgml/ref/create_table.sgml | 24 ++++--
src/backend/catalog/heap.c | 2 +
src/backend/catalog/index.c | 2 +
src/backend/catalog/pg_constraint.c | 53 +++++++++++-
src/backend/commands/tablecmds.c | 97 +++++++++++++++++++--
src/backend/commands/trigger.c | 2 +
src/backend/commands/typecmds.c | 2 +
src/backend/nodes/copyfuncs.c | 1 +
src/backend/nodes/equalfuncs.c | 1 +
src/backend/nodes/outfuncs.c | 1 +
src/backend/parser/gram.y | 134 +++++++++++++++++++++++++-----
src/backend/utils/adt/ri_triggers.c | 115 ++++++++++++++++++-------
src/backend/utils/adt/ruleutils.c | 10 +++
src/backend/utils/cache/relcache.c | 2 +-
src/include/catalog/catversion.h | 2 +-
src/include/catalog/pg_constraint.h | 11 ++-
src/include/nodes/parsenodes.h | 1 +
src/test/regress/expected/foreign_key.out | 71 ++++++++++++++++
src/test/regress/sql/foreign_key.sql | 51 ++++++++++++
22 files changed, 557 insertions(+), 72 deletions(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Fujii Masao 2021-12-08 14:33:43 pgsql: postgres_fdw: Report warning when timeout expires while getting
Previous Message Amit Kapila 2021-12-08 10:01:12 pgsql: Fix origin timestamp during decoding of ROLLBACK PREPARED operat