diff options
| author | Tom Lane | 2007-05-11 20:17:15 +0000 |
|---|---|---|
| committer | Tom Lane | 2007-05-11 20:17:15 +0000 |
| commit | d8326119c8885e938eff79e22fce6c1cb19379f4 (patch) | |
| tree | 7c482ccb7b0d0aec7551585347a422e495a67d4e /src/test | |
| parent | 3b6afdd7f9d38c33f21e5211ccbbcd3514312372 (diff) | |
Fix my oversight in enabling domains-of-domains: ALTER DOMAIN ADD CONSTRAINT
needs to check the new constraint against columns of derived domains too.
Also, make it error out if the domain to be modified is used within any
composite-type columns. Eventually we should support that case, but it seems
a bit painful, and not suitable for a back-patch. For the moment just let the
user know we can't do it.
Backpatch to 8.2, which is the only released version that allows nested
domains. Possibly the other part should be back-patched further.
Diffstat (limited to 'src/test')
| -rw-r--r-- | src/test/regress/expected/domain.out | 29 | ||||
| -rw-r--r-- | src/test/regress/sql/domain.sql | 31 |
2 files changed, 60 insertions, 0 deletions
diff --git a/src/test/regress/expected/domain.out b/src/test/regress/expected/domain.out index e01fc7cadc..c7d5b50334 100644 --- a/src/test/regress/expected/domain.out +++ b/src/test/regress/expected/domain.out @@ -438,3 +438,32 @@ select doubledecrement(3); -- good 1 (1 row) +-- Check that ALTER DOMAIN tests columns of derived types +create domain posint as int4; +-- Currently, this doesn't work for composite types, but verify it complains +create type ddtest1 as (f1 posint); +create table ddtest2(f1 ddtest1); +insert into ddtest2 values(row(-1)); +alter domain posint add constraint c1 check(value >= 0); +ERROR: cannot alter type "posint" because column "ddtest2"."f1" uses it +drop table ddtest2; +create table ddtest2(f1 ddtest1[]); +insert into ddtest2 values('{(-1)}'); +alter domain posint add constraint c1 check(value >= 0); +ERROR: cannot alter type "posint" because column "ddtest2"."f1" uses it +drop table ddtest2; +alter domain posint add constraint c1 check(value >= 0); +create domain posint2 as posint check (value % 2 = 0); +create table ddtest2(f1 posint2); +insert into ddtest2 values(11); -- fail +ERROR: value for domain posint2 violates check constraint "posint2_check" +insert into ddtest2 values(-2); -- fail +ERROR: value for domain posint2 violates check constraint "c1" +insert into ddtest2 values(2); +alter domain posint add constraint c2 check(value >= 10); -- fail +ERROR: column "f1" of table "ddtest2" contains values that violate the new constraint +alter domain posint add constraint c2 check(value > 0); -- OK +drop table ddtest2; +drop type ddtest1; +drop domain posint cascade; +NOTICE: drop cascades to type posint2 diff --git a/src/test/regress/sql/domain.sql b/src/test/regress/sql/domain.sql index 4e103172ed..7da9971991 100644 --- a/src/test/regress/sql/domain.sql +++ b/src/test/regress/sql/domain.sql @@ -351,3 +351,34 @@ select doubledecrement(0); -- fail before call select doubledecrement(1); -- fail at assignment to v select doubledecrement(2); -- fail at return select doubledecrement(3); -- good + +-- Check that ALTER DOMAIN tests columns of derived types + +create domain posint as int4; + +-- Currently, this doesn't work for composite types, but verify it complains +create type ddtest1 as (f1 posint); +create table ddtest2(f1 ddtest1); +insert into ddtest2 values(row(-1)); +alter domain posint add constraint c1 check(value >= 0); +drop table ddtest2; + +create table ddtest2(f1 ddtest1[]); +insert into ddtest2 values('{(-1)}'); +alter domain posint add constraint c1 check(value >= 0); +drop table ddtest2; + +alter domain posint add constraint c1 check(value >= 0); + +create domain posint2 as posint check (value % 2 = 0); +create table ddtest2(f1 posint2); +insert into ddtest2 values(11); -- fail +insert into ddtest2 values(-2); -- fail +insert into ddtest2 values(2); + +alter domain posint add constraint c2 check(value >= 10); -- fail +alter domain posint add constraint c2 check(value > 0); -- OK + +drop table ddtest2; +drop type ddtest1; +drop domain posint cascade; |
