diff options
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/regress/expected/alter_table.out | 10 | ||||
-rw-r--r-- | src/test/regress/expected/foreign_key.out | 9 | ||||
-rw-r--r-- | src/test/regress/sql/alter_table.sql | 13 | ||||
-rw-r--r-- | src/test/regress/sql/foreign_key.sql | 7 |
4 files changed, 39 insertions, 0 deletions
diff --git a/src/test/regress/expected/alter_table.out b/src/test/regress/expected/alter_table.out index d79a65c983a..082a0be4782 100644 --- a/src/test/regress/expected/alter_table.out +++ b/src/test/regress/expected/alter_table.out @@ -273,6 +273,9 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5; CREATE TABLE tmp2 (a int primary key); NOTICE: CREATE TABLE/PRIMARY KEY will create implicit index 'tmp2_pkey' for table 'tmp2' CREATE TABLE tmp3 (a int, b int); +CREATE TABLE tmp4 (a int, b int, unique(a,b)); +NOTICE: CREATE TABLE/UNIQUE will create implicit index 'tmp4_a_key' for table 'tmp4' +CREATE TABLE tmp5 (a int, b int); -- Insert rows into tmp2 (pktable) INSERT INTO tmp2 values (1); INSERT INTO tmp2 values (2); @@ -299,6 +302,13 @@ 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) +-- 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) +ERROR: UNIQUE constraint matching given keys for referenced table "tmp4" not found +DROP TABLE tmp5; +DROP TABLE tmp4; DROP TABLE tmp3; NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "tmp2" NOTICE: DROP TABLE implicitly drops referential integrity trigger from table "tmp2" diff --git a/src/test/regress/expected/foreign_key.out b/src/test/regress/expected/foreign_key.out index 41263247556..075b6aa2f87 100644 --- a/src/test/regress/expected/foreign_key.out +++ b/src/test/regress/expected/foreign_key.out @@ -703,3 +703,12 @@ ERROR: table "fktable_fail1" does not exist DROP TABLE FKTABLE_FAIL2; ERROR: table "fktable_fail2" does not exist DROP TABLE PKTABLE; +-- Test for referencing column number smaller than referenced constraint +CREATE TABLE PKTABLE (ptest1 int, ptest2 int, UNIQUE(ptest1, ptest2)); +NOTICE: CREATE TABLE/UNIQUE will create implicit index 'pktable_ptest1_key' for table 'pktable' +CREATE TABLE FKTABLE_FAIL1 (ftest1 int REFERENCES pktable(ptest1)); +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 +DROP TABLE FKTABLE_FAIL1; +ERROR: table "fktable_fail1" does not exist +DROP TABLE PKTABLE; diff --git a/src/test/regress/sql/alter_table.sql b/src/test/regress/sql/alter_table.sql index cb7b9a2a469..f90710f8d96 100644 --- a/src/test/regress/sql/alter_table.sql +++ b/src/test/regress/sql/alter_table.sql @@ -169,6 +169,10 @@ CREATE TABLE tmp2 (a int primary key); CREATE TABLE tmp3 (a int, b int); +CREATE TABLE tmp4 (a int, b int, unique(a,b)); + +CREATE TABLE tmp5 (a int, b int); + -- Insert rows into tmp2 (pktable) INSERT INTO tmp2 values (1); INSERT INTO tmp2 values (2); @@ -195,6 +199,15 @@ DELETE FROM tmp3 where a=5; -- Try (and succeed) ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full; +-- 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; + +DROP TABLE tmp5; + +DROP TABLE tmp4; + DROP TABLE tmp3; DROP TABLE tmp2; diff --git a/src/test/regress/sql/foreign_key.sql b/src/test/regress/sql/foreign_key.sql index ac29e50579c..91ff0aafe58 100644 --- a/src/test/regress/sql/foreign_key.sql +++ b/src/test/regress/sql/foreign_key.sql @@ -418,3 +418,10 @@ CREATE TABLE FKTABLE_FAIL2 ( ftest1 int, CONSTRAINT fkfail1 FOREIGN KEY (ftest1) DROP TABLE FKTABLE_FAIL1; DROP TABLE FKTABLE_FAIL2; DROP TABLE PKTABLE; + +-- Test for referencing column number smaller than referenced constraint +CREATE TABLE PKTABLE (ptest1 int, ptest2 int, UNIQUE(ptest1, ptest2)); +CREATE TABLE FKTABLE_FAIL1 (ftest1 int REFERENCES pktable(ptest1)); + +DROP TABLE FKTABLE_FAIL1; +DROP TABLE PKTABLE; |