From: Peter Eisentraut <peter@eisentraut.org>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Allow specifying column list for foreign key ON DELETE SET actio
Date: Wed, 08 Dec 2021 10:27:56 +0000
Message-ID: <E1muuB2-0004XM-QE@gemulon.postgresql.org> (raw)
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....
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(-)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-committers@postgresql.org
Cc: peter@eisentraut.org
Subject: Re: pgsql: Allow specifying column list for foreign key ON DELETE SET actio
In-Reply-To: <E1muuB2-0004XM-QE@gemulon.postgresql.org>
References: <E1muuB2-0004XM-QE@gemulon.postgresql.org>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox