diff options
author | Peter Eisentraut <peter@eisentraut.org> | 2024-03-20 09:29:08 +0100 |
---|---|---|
committer | Peter Eisentraut <peter@eisentraut.org> | 2024-03-20 10:05:37 +0100 |
commit | e5da0fe3c22b34c4433f1729e88495554b5331ed (patch) | |
tree | fa99ee64f20e482db38cf3c45d849510a9e7507a /src/test | |
parent | c9c260decd239159277c1baad9d929ebcdf2491e (diff) | |
download | postgresql-e5da0fe3c22b34c4433f1729e88495554b5331ed.tar.gz postgresql-e5da0fe3c22b34c4433f1729e88495554b5331ed.zip |
Catalog domain not-null constraints
This applies the explicit catalog representation of not-null
constraints introduced by b0e96f3119 for table constraints also to
domain not-null constraints.
Reviewed-by: Aleksander Alekseev <aleksander@timescale.com>
Reviewed-by: jian he <jian.universality@gmail.com>
Discussion: https://www.postgresql.org/message-id/flat/9ec24d7b-633d-463a-84c6-7acff769c9e8%40eisentraut.org
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/domain.out | 62 | ||||
-rw-r--r-- | src/test/regress/sql/domain.sql | 29 |
2 files changed, 79 insertions, 12 deletions
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out index e70aebd70c0..dc58793e3f5 100644 --- a/src/test/regress/expected/domain.out +++ b/src/test/regress/expected/domain.out @@ -798,6 +798,42 @@ alter domain con drop constraint nonexistent; ERROR: constraint "nonexistent" of domain "con" does not exist alter domain con drop constraint if exists nonexistent; NOTICE: constraint "nonexistent" of domain "con" does not exist, skipping +-- not-null constraints +create domain connotnull integer; +create table domconnotnulltest +( col1 connotnull +, col2 connotnull +); +insert into domconnotnulltest default values; +alter domain connotnull add not null value; -- fails +ERROR: column "col1" of table "domconnotnulltest" contains null values +update domconnotnulltest set col1 = 5; +alter domain connotnull add not null value; -- fails +ERROR: column "col2" of table "domconnotnulltest" contains null values +update domconnotnulltest set col2 = 6; +alter domain connotnull add constraint constr1 not null value; +select count(*) from pg_constraint where contypid = 'connotnull'::regtype and contype = 'n'; + count +------- + 1 +(1 row) + +alter domain connotnull add constraint constr1bis not null value; -- redundant +select count(*) from pg_constraint where contypid = 'connotnull'::regtype and contype = 'n'; + count +------- + 1 +(1 row) + +update domconnotnulltest set col1 = null; -- fails +ERROR: domain connotnull does not allow null values +alter domain connotnull drop constraint constr1; +update domconnotnulltest set col1 = null; +drop domain connotnull cascade; +NOTICE: drop cascades to 2 other objects +DETAIL: drop cascades to column col2 of table domconnotnulltest +drop cascades to column col1 of table domconnotnulltest +drop table domconnotnulltest; -- Test ALTER DOMAIN .. CONSTRAINT .. NOT VALID create domain things AS INT; CREATE TABLE thethings (stuff things); @@ -1223,12 +1259,13 @@ SELECT * FROM information_schema.column_domain_usage SELECT * FROM information_schema.domain_constraints WHERE domain_name IN ('con', 'dom', 'pos_int', 'things') ORDER BY constraint_name; - constraint_catalog | constraint_schema | constraint_name | domain_catalog | domain_schema | domain_name | is_deferrable | initially_deferred ---------------------+-------------------+-----------------+----------------+---------------+-------------+---------------+-------------------- - regression | public | con_check | regression | public | con | NO | NO - regression | public | meow | regression | public | things | NO | NO - regression | public | pos_int_check | regression | public | pos_int | NO | NO -(3 rows) + constraint_catalog | constraint_schema | constraint_name | domain_catalog | domain_schema | domain_name | is_deferrable | initially_deferred +--------------------+-------------------+------------------+----------------+---------------+-------------+---------------+-------------------- + regression | public | con_check | regression | public | con | NO | NO + regression | public | meow | regression | public | things | NO | NO + regression | public | pos_int_check | regression | public | pos_int | NO | NO + regression | public | pos_int_not_null | regression | public | pos_int | NO | NO +(4 rows) SELECT * FROM information_schema.domains WHERE domain_name IN ('con', 'dom', 'pos_int', 'things') @@ -1247,10 +1284,11 @@ SELECT * FROM information_schema.check_constraints FROM information_schema.domain_constraints WHERE domain_name IN ('con', 'dom', 'pos_int', 'things')) ORDER BY constraint_name; - constraint_catalog | constraint_schema | constraint_name | check_clause ---------------------+-------------------+-----------------+-------------- - regression | public | con_check | (VALUE > 0) - regression | public | meow | (VALUE < 11) - regression | public | pos_int_check | (VALUE > 0) -(3 rows) + constraint_catalog | constraint_schema | constraint_name | check_clause +--------------------+-------------------+------------------+------------------- + regression | public | con_check | (VALUE > 0) + regression | public | meow | (VALUE < 11) + regression | public | pos_int_check | (VALUE > 0) + regression | public | pos_int_not_null | VALUE IS NOT NULL +(4 rows) diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql index 813048c19f5..ae1b7fbf97a 100644 --- a/src/test/regress/sql/domain.sql +++ b/src/test/regress/sql/domain.sql @@ -469,6 +469,35 @@ insert into domcontest values (42); alter domain con drop constraint nonexistent; alter domain con drop constraint if exists nonexistent; +-- not-null constraints +create domain connotnull integer; +create table domconnotnulltest +( col1 connotnull +, col2 connotnull +); + +insert into domconnotnulltest default values; +alter domain connotnull add not null value; -- fails + +update domconnotnulltest set col1 = 5; +alter domain connotnull add not null value; -- fails + +update domconnotnulltest set col2 = 6; + +alter domain connotnull add constraint constr1 not null value; +select count(*) from pg_constraint where contypid = 'connotnull'::regtype and contype = 'n'; +alter domain connotnull add constraint constr1bis not null value; -- redundant +select count(*) from pg_constraint where contypid = 'connotnull'::regtype and contype = 'n'; + +update domconnotnulltest set col1 = null; -- fails + +alter domain connotnull drop constraint constr1; + +update domconnotnulltest set col1 = null; + +drop domain connotnull cascade; +drop table domconnotnulltest; + -- Test ALTER DOMAIN .. CONSTRAINT .. NOT VALID create domain things AS INT; CREATE TABLE thethings (stuff things); |