mirror of
https://github.com/postgres/postgres.git
synced 2025-12-07 12:02:30 +03:00
Break transformCreateStmt() into multiple routines and make
transformAlterStmt() use these routines, instead of having lots of duplicate (not to mention should-have-been-duplicate) code. Adding a column with a CHECK constraint actually works now, and the tests to reject unsupported DEFAULT and NOT NULL clauses actually fire now. ALTER TABLE ADD PRIMARY KEY works, modulo having to have created the column(s) NOT NULL already.
This commit is contained in:
@@ -287,25 +287,25 @@ INSERT INTO tmp3 values (1,20);
|
||||
INSERT INTO tmp3 values (5,50);
|
||||
-- Try (and fail) to add constraint due to invalid source columns
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key(c) references tmp2 match full;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: columns referenced in foreign key constraint not found.
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: ALTER TABLE: column "c" referenced in foreign key constraint does not exist
|
||||
-- Try (and fail) to add constraint due to invalide destination columns explicitly given
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key(a) references tmp2(b) match full;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "tmp2" not found
|
||||
-- Try (and fail) to add constraint due to invalid data
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: tmpconstr referential integrity violation - key referenced from tmp3 not found in tmp2
|
||||
-- Delete failing row
|
||||
DELETE FROM tmp3 where a=5;
|
||||
-- Try (and succeed)
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
-- Try (and fail) to create constraint from tmp5(a) to tmp4(a) - unique constraint on
|
||||
-- tmp4 is a,b
|
||||
ALTER TABLE tmp5 add constraint tmpconstr foreign key(a) references tmp4(a) match full;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "tmp4" not found
|
||||
DROP TABLE tmp5;
|
||||
DROP TABLE tmp4;
|
||||
@@ -321,13 +321,13 @@ NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'pktable_pkey' for
|
||||
CREATE TEMP TABLE FKTABLE (ftest1 text);
|
||||
-- This next should fail, because text=int does not exist
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'text' and 'integer'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- This should also fail for the same reason, but here we
|
||||
-- give the column name
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'text' and 'integer'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- This should succeed, even though they are different types
|
||||
@@ -335,10 +335,10 @@ ERROR: Unable to identify an operator '=' for types 'text' and 'integer'
|
||||
DROP TABLE FKTABLE;
|
||||
CREATE TEMP TABLE FKTABLE (ftest1 varchar);
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
-- As should this
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1) references pktable(ptest1);
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
DROP TABLE pktable;
|
||||
NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "fktable"
|
||||
NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "fktable"
|
||||
@@ -349,7 +349,7 @@ NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'pktable_pkey' for
|
||||
-- This should fail, because we just chose really odd types
|
||||
CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 datetime);
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2) references pktable;
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'cidr' and 'integer'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- Again, so should this...
|
||||
@@ -357,7 +357,7 @@ DROP TABLE FKTABLE;
|
||||
CREATE TEMP TABLE FKTABLE (ftest1 cidr, ftest2 datetime);
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
|
||||
references pktable(ptest1, ptest2);
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'cidr' and 'integer'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- This fails because we mixed up the column ordering
|
||||
@@ -365,13 +365,13 @@ DROP TABLE FKTABLE;
|
||||
CREATE TEMP TABLE FKTABLE (ftest1 int, ftest2 text);
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest1, ftest2)
|
||||
references pktable(ptest2, ptest1);
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'integer' and 'text'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- As does this...
|
||||
ALTER TABLE FKTABLE ADD FOREIGN KEY(ftest2, ftest1)
|
||||
references pktable(ptest1, ptest2);
|
||||
NOTICE: ALTER TABLE ... ADD CONSTRAINT will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
NOTICE: ALTER TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: Unable to identify an operator '=' for types 'text' and 'integer'
|
||||
You will have to retype this query using an explicit cast
|
||||
-- temp tables should go away by themselves, need not drop them.
|
||||
|
||||
@@ -694,7 +694,7 @@ CREATE TABLE PKTABLE (ptest1 int PRIMARY KEY);
|
||||
NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'pktable_pkey' for table 'pktable'
|
||||
CREATE TABLE FKTABLE_FAIL1 ( ftest1 int, CONSTRAINT fkfail1 FOREIGN KEY (ftest2) REFERENCES PKTABLE);
|
||||
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: columns referenced in foreign key constraint not found.
|
||||
ERROR: CREATE TABLE: column "ftest2" referenced in foreign key constraint does not exist
|
||||
CREATE TABLE FKTABLE_FAIL2 ( ftest1 int, CONSTRAINT fkfail1 FOREIGN KEY (ftest1) REFERENCES PKTABLE(ptest2));
|
||||
NOTICE: CREATE TABLE will create implicit trigger(s) for FOREIGN KEY check(s)
|
||||
ERROR: UNIQUE constraint matching given keys for referenced table "pktable" not found
|
||||
|
||||
Reference in New Issue
Block a user