mirror of
https://github.com/postgres/postgres.git
synced 2025-07-09 22:41:56 +03:00
Well, here's the first pass on regression
tests for the Foreign Key support in 7.0 which was made against a CVS copy from this afternoon. This modifies src/test/regress/sql/run_check.tests src/test/regress/sql/alter_table.sql src/test/regress/expected/alter_table.out src/test/regress/sql/foreign_key.sql src/test/regress/expected/foreign_key.out sszabo@bigpanda.co
This commit is contained in:
@ -269,3 +269,27 @@ SELECT unique1 FROM tenk1 WHERE unique1 < 5;
|
||||
4
|
||||
(5 rows)
|
||||
|
||||
-- FOREIGN KEY CONSTRAINT adding TEST
|
||||
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);
|
||||
-- Insert rows into tmp2 (pktable)
|
||||
INSERT INTO tmp2 values (1);
|
||||
INSERT INTO tmp2 values (2);
|
||||
INSERT INTO tmp2 values (3);
|
||||
INSERT INTO tmp2 values (4);
|
||||
-- Insert rows into tmp3
|
||||
INSERT INTO tmp3 values (1,10);
|
||||
INSERT INTO tmp3 values (1,20);
|
||||
INSERT INTO tmp3 values (5,50);
|
||||
-- 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)
|
||||
ERROR: <unnamed> 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)
|
||||
DROP TABLE tmp3
|
||||
DROP TABLE tmp2
|
||||
|
@ -163,3 +163,33 @@ ALTER TABLE ten_k RENAME TO tenk1;
|
||||
-- 5 values, sorted
|
||||
SELECT unique1 FROM tenk1 WHERE unique1 < 5;
|
||||
|
||||
-- FOREIGN KEY CONSTRAINT adding TEST
|
||||
|
||||
CREATE TABLE tmp2 (a int primary key);
|
||||
|
||||
CREATE TABLE tmp3 (a int, b int);
|
||||
|
||||
-- Insert rows into tmp2 (pktable)
|
||||
INSERT INTO tmp2 values (1);
|
||||
INSERT INTO tmp2 values (2);
|
||||
INSERT INTO tmp2 values (3);
|
||||
INSERT INTO tmp2 values (4);
|
||||
|
||||
-- Insert rows into tmp3
|
||||
INSERT INTO tmp3 values (1,10);
|
||||
INSERT INTO tmp3 values (1,20);
|
||||
INSERT INTO tmp3 values (5,50);
|
||||
|
||||
-- Try (and fail) to add constraint due to invalid data
|
||||
ALTER TABLE tmp3 add constraint tmpconstr foreign key (a) references tmp2 match full;
|
||||
|
||||
-- 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;
|
||||
|
||||
DROP TABLE tmp3
|
||||
|
||||
DROP TABLE tmp2
|
||||
|
||||
|
@ -119,6 +119,7 @@ parallel group5
|
||||
test alter_table
|
||||
test portals_p2
|
||||
test rules
|
||||
test foreign_key
|
||||
endparallel
|
||||
|
||||
# ----------
|
||||
|
Reference in New Issue
Block a user