Skip to content

Commit 6e79358

Browse files
committed
Fix pg_get_constraintdef for NOT NULL constraints on domains
We added pg_constraint rows for all not-null constraints, first for tables and later for domains; but while the ones for tables were reverted, the ones for domains were not. However, we did accidentally revert ruleutils.c support for the ones on domains in 6f8bb7c, which breaks running pg_get_constraintdef() on them. Put that back. This is only needed in branch 17, because we've reinstated this code in branch master with commit 14e87ff. Add some new tests in both branches. I couldn't find anything else that needs de-reverting. Reported-by: Erki Eessaar <erki.eessaar@taltech.ee> Reviewed-by: Magnus Hagander <magnus@hagander.net> Discussion: https://postgr.es/m/AS8PR01MB75110350415AAB8BBABBA1ECFE222@AS8PR01MB7511.eurprd01.prod.exchangelabs.com
1 parent 7786717 commit 6e79358

File tree

3 files changed

+30
-0
lines changed

3 files changed

+30
-0
lines changed

src/backend/utils/adt/ruleutils.c

+5
Original file line numberDiff line numberDiff line change
@@ -2499,6 +2499,11 @@ pg_get_constraintdef_worker(Oid constraintId, bool fullCommand,
24992499
conForm->connoinherit ? " NO INHERIT" : "");
25002500
break;
25012501
}
2502+
2503+
case CONSTRAINT_NOTNULL:
2504+
appendStringInfoString(&buf, "NOT NULL");
2505+
break;
2506+
25022507
case CONSTRAINT_TRIGGER:
25032508

25042509
/*

src/test/regress/expected/domain.out

+14
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,20 @@ update domnotnull set col1 = null; -- fails
743743
ERROR: domain dnotnulltest does not allow null values
744744
alter domain dnotnulltest drop not null;
745745
update domnotnull set col1 = null;
746+
update domnotnull set col1 = 5;
747+
-- these constraints can also be added and removed by name
748+
alter domain dnotnulltest add constraint dnotnulltest_notnull not null;
749+
update domnotnull set col1 = null; -- fails
750+
ERROR: domain dnotnulltest does not allow null values
751+
select conname, pg_get_constraintdef(oid) from pg_constraint
752+
where contypid = 'dnotnulltest'::regtype;
753+
conname | pg_get_constraintdef
754+
----------------------+----------------------
755+
dnotnulltest_notnull | NOT NULL
756+
(1 row)
757+
758+
alter domain dnotnulltest drop constraint dnotnulltest_notnull;
759+
update domnotnull set col1 = null;
746760
drop domain dnotnulltest cascade;
747761
NOTICE: drop cascades to 2 other objects
748762
DETAIL: drop cascades to column col2 of table domnotnull

src/test/regress/sql/domain.sql

+11
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,17 @@ alter domain dnotnulltest drop not null;
429429

430430
update domnotnull set col1 = null;
431431

432+
update domnotnull set col1 = 5;
433+
434+
-- these constraints can also be added and removed by name
435+
alter domain dnotnulltest add constraint dnotnulltest_notnull not null;
436+
update domnotnull set col1 = null; -- fails
437+
select conname, pg_get_constraintdef(oid) from pg_constraint
438+
where contypid = 'dnotnulltest'::regtype;
439+
440+
alter domain dnotnulltest drop constraint dnotnulltest_notnull;
441+
update domnotnull set col1 = null;
442+
432443
drop domain dnotnulltest cascade;
433444

434445
-- Test ALTER DOMAIN .. DEFAULT ..

0 commit comments

Comments
 (0)