1
0
mirror of https://github.com/postgres/postgres.git synced 2025-12-15 02:22:24 +03:00

Determine the set of constraints applied to a domain at executor

startup, not in the parser; this allows ALTER DOMAIN to work correctly
with domain constraint operations stored in rules.  Rod Taylor;
code review by Tom Lane.
This commit is contained in:
Tom Lane
2003-02-03 21:15:45 +00:00
parent 464598b637
commit 3752e85bad
24 changed files with 524 additions and 339 deletions

View File

@@ -257,14 +257,49 @@ ERROR: ALTER DOMAIN: Relation "domcontest" attribute "col1" contains values tha
alter domain con add constraint t check (VALUE < 34);
alter domain con add check (VALUE > 0);
insert into domcontest values (-5); -- fails
ERROR: ExecEvalConstraintTest: Domain con constraint $1 failed
ERROR: ExecEvalCoerceToDomain: Domain con constraint $1 failed
insert into domcontest values (42); -- fails
ERROR: ExecEvalConstraintTest: Domain con constraint t failed
ERROR: ExecEvalCoerceToDomain: Domain con constraint t failed
insert into domcontest values (5);
alter domain con drop constraint t;
insert into domcontest values (-5); --fails
ERROR: ExecEvalConstraintTest: Domain con constraint $1 failed
ERROR: ExecEvalCoerceToDomain: Domain con constraint $1 failed
insert into domcontest values (42);
-- Confirm ALTER DOMAIN with RULES.
create table domtab (col1 integer);
create domain dom as integer;
create view domview as select cast(col1 as dom) from domtab;
insert into domtab (col1) values (null);
insert into domtab (col1) values (5);
select * from domview;
col1
------
5
(2 rows)
alter domain dom set not null;
select * from domview; -- fail
ERROR: Domain dom does not allow NULL values
alter domain dom drop not null;
select * from domview;
col1
------
5
(2 rows)
alter domain dom add constraint domchkgt6 check(value > 6);
select * from domview; --fail
ERROR: ExecEvalCoerceToDomain: Domain dom constraint domchkgt6 failed
alter domain dom drop constraint domchkgt6 restrict;
select * from domview;
col1
------
5
(2 rows)
-- cleanup
drop domain ddef1 restrict;
drop domain ddef2 restrict;

View File

@@ -224,6 +224,26 @@ alter domain con drop constraint t;
insert into domcontest values (-5); --fails
insert into domcontest values (42);
-- Confirm ALTER DOMAIN with RULES.
create table domtab (col1 integer);
create domain dom as integer;
create view domview as select cast(col1 as dom) from domtab;
insert into domtab (col1) values (null);
insert into domtab (col1) values (5);
select * from domview;
alter domain dom set not null;
select * from domview; -- fail
alter domain dom drop not null;
select * from domview;
alter domain dom add constraint domchkgt6 check(value > 6);
select * from domview; --fail
alter domain dom drop constraint domchkgt6 restrict;
select * from domview;
-- cleanup
drop domain ddef1 restrict;
drop domain ddef2 restrict;