aboutsummaryrefslogtreecommitdiff
path: root/src/backend/utils/adt/ruleutils.c
diff options
context:
space:
mode:
authorPeter Eisentraut <peter@eisentraut.org>2021-12-08 11:09:44 +0100
committerPeter Eisentraut <peter@eisentraut.org>2021-12-08 11:13:57 +0100
commitd6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a (patch)
tree621d033b72ab7da8a21acb729b41c015b6322747 /src/backend/utils/adt/ruleutils.c
parente464cb7af317e216fef9bfe19a7c4df542817012 (diff)
downloadpostgresql-d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a.tar.gz
postgresql-d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a.zip
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/backend/utils/adt/ruleutils.c')
-rw-r--r--src/backend/utils/adt/ruleutils.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/backend/utils/adt/ruleutils.c b/src/backend/utils/adt/ruleutils.c
index 6b4022c3bcc..8da525c715b 100644
--- a/src/backend/utils/adt/ruleutils.c
+++ b/src/backend/utils/adt/ruleutils.c
@@ -2287,6 +2287,16 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
if (string)
appendStringInfo(&buf, " ON DELETE %s", string);
+ /* Add columns specified to SET NULL or SET DEFAULT if provided. */
+ val = SysCacheGetAttr(CONSTROID, tup,
+ Anum_pg_constraint_confdelsetcols, &isnull);
+ if (!isnull)
+ {
+ appendStringInfo(&buf, " (");
+ decompile_column_index_array(val, conForm->conrelid, &buf);
+ appendStringInfo(&buf, ")");
+ }
+
break;
}
case CONSTRAINT_PRIMARY: