update existing tests

improve-drop-trigger2
Onur Tirtir 2020-03-04 11:21:38 +03:00
parent badf59852c
commit 9e9c345d8f
6 changed files with 95 additions and 5 deletions

View File

@ -24,6 +24,9 @@ SELECT create_distributed_table('t1', 'a');
(1 row) (1 row)
SELECT create_reference_table('r1'); SELECT create_reference_table('r1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------

View File

@ -1271,6 +1271,9 @@ BEGIN;
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
NOTICE: Copying data from local table... NOTICE: Copying data from local table...
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1295,6 +1298,9 @@ BEGIN;
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
NOTICE: Copying data from local table... NOTICE: Copying data from local table...
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1316,6 +1322,9 @@ BEGIN;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------

View File

@ -745,6 +745,9 @@ CREATE TABLE referencing_table(id int, ref_id int DEFAULT -1, FOREIGN KEY (ref_i
INSERT INTO referenced_table VALUES (1,1), (2,2), (3,3); INSERT INTO referenced_table VALUES (1,1), (2,2), (3,3);
INSERT INTO referencing_table VALUES (1,1), (2,2), (3,3); INSERT INTO referencing_table VALUES (1,1), (2,2), (3,3);
SELECT create_reference_table('referenced_table'); SELECT create_reference_table('referenced_table');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
NOTICE: Copying data from local table... NOTICE: Copying data from local table...
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -859,12 +862,18 @@ CREATE TABLE referenced_table(test_column int, test_column2 int, PRIMARY KEY(tes
CREATE TABLE referenced_table2(test_column int, test_column2 int, PRIMARY KEY(test_column2)); CREATE TABLE referenced_table2(test_column int, test_column2 int, PRIMARY KEY(test_column2));
CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE); CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE);
SELECT create_reference_table('referenced_table'); SELECT create_reference_table('referenced_table');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
SELECT create_reference_table('referenced_table2'); SELECT create_reference_table('referenced_table2');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -985,6 +994,7 @@ CREATE TABLE referenced_table2(test_column int, test_column2 int, PRIMARY KEY(te
CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE); CREATE TABLE referencing_table(id int, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE);
BEGIN; BEGIN;
SELECT create_reference_table('referenced_table'); SELECT create_reference_table('referenced_table');
WARNING: should not create foreign key constraint in this way
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1125,6 +1135,12 @@ CREATE TABLE referenced_table(test_column int, test_column2 int UNIQUE, PRIMARY
CREATE TABLE referencing_table(id int PRIMARY KEY, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE); CREATE TABLE referencing_table(id int PRIMARY KEY, ref_id int, FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE);
CREATE TABLE referencing_table2(id int, ref_id int, FOREIGN KEY (ref_id) REFERENCES referenced_table(test_column2) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referencing_table(id) ON DELETE CASCADE); CREATE TABLE referencing_table2(id int, ref_id int, FOREIGN KEY (ref_id) REFERENCES referenced_table(test_column2) ON DELETE CASCADE, FOREIGN KEY (id) REFERENCES referencing_table(id) ON DELETE CASCADE);
SELECT create_reference_table('referenced_table'); SELECT create_reference_table('referenced_table');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1304,6 +1320,9 @@ BEGIN;
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i; INSERT INTO test_table_2 SELECT i, i FROM generate_series(0,100) i;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
NOTICE: Copying data from local table... NOTICE: Copying data from local table...
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1321,6 +1340,9 @@ BEGIN;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1341,6 +1363,9 @@ COMMIT;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1401,6 +1426,9 @@ ERROR: table "test_table_1" does not exist
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1426,6 +1454,9 @@ BEGIN;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1451,6 +1482,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1475,6 +1509,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
BEGIN; BEGIN;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1499,6 +1536,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1524,6 +1564,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
BEGIN; BEGIN;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1549,6 +1592,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int); CREATE TABLE test_table_1(id int PRIMARY KEY, id2 int);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1585,6 +1631,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
BEGIN; BEGIN;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1611,6 +1660,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1636,6 +1688,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1664,6 +1719,9 @@ CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
BEGIN; BEGIN;
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1690,6 +1748,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
@ -1722,6 +1783,9 @@ DROP TABLE test_table_1, test_table_2;
CREATE TABLE test_table_1(id int PRIMARY KEY); CREATE TABLE test_table_1(id int PRIMARY KEY);
CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id)); CREATE TABLE test_table_2(id int PRIMARY KEY, value_1 int, FOREIGN KEY(value_1) REFERENCES test_table_1(id));
SELECT create_reference_table('test_table_1'); SELECT create_reference_table('test_table_1');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------

View File

@ -836,7 +836,7 @@ SELECT create_distributed_table('referenced_by_reference_table', 'id');
CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_by_reference_table(id)); CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_by_reference_table(id));
SELECT create_reference_table('reference_table'); SELECT create_reference_table('reference_table');
ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported
DETAIL: A reference table can only have reference keys to other reference tables DETAIL: A reference table can only have reference keys to other reference tables or a local table in coordinator
-- test foreign key creation on CREATE TABLE from + to reference table -- test foreign key creation on CREATE TABLE from + to reference table
DROP TABLE reference_table; DROP TABLE reference_table;
CREATE TABLE reference_table(id int PRIMARY KEY, referencing_column int); CREATE TABLE reference_table(id int PRIMARY KEY, referencing_column int);
@ -860,7 +860,8 @@ NOTICE: drop cascades to constraint reference_table_second_referencing_column_f
CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_local_table(id)); CREATE TABLE reference_table(id int, referencing_column int REFERENCES referenced_local_table(id));
SELECT create_reference_table('reference_table'); SELECT create_reference_table('reference_table');
ERROR: cannot create foreign key constraint ERROR: cannot create foreign key constraint
DETAIL: Referenced table must be a distributed table or a reference table. DETAIL: Local table having a foreign key constraint to another local table cannot be upgraded to a reference table
HINT: To define foreign key constraint from a reference table to a local table, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
-- test foreign key creation on CREATE TABLE on self referencing reference table -- test foreign key creation on CREATE TABLE on self referencing reference table
CREATE TABLE self_referencing_reference_table( CREATE TABLE self_referencing_reference_table(
id int, id int,
@ -886,7 +887,7 @@ SELECT create_reference_table('reference_table');
ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_by_reference_table(id); ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_by_reference_table(id);
ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported ERROR: cannot create foreign key constraint since foreign keys from reference tables to distributed tables are not supported
DETAIL: A reference table can only have reference keys to other reference tables DETAIL: A reference table can only have reference keys to other reference tables or a local table in coordinator
-- test foreign key creation on ALTER TABLE to reference table -- test foreign key creation on ALTER TABLE to reference table
CREATE TABLE references_to_reference_table(id int, referencing_column int); CREATE TABLE references_to_reference_table(id int, referencing_column int);
SELECT create_distributed_table('references_to_reference_table', 'referencing_column'); SELECT create_distributed_table('references_to_reference_table', 'referencing_column');
@ -919,8 +920,9 @@ SELECT create_reference_table('reference_table');
(1 row) (1 row)
ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_local_table(id); ALTER TABLE reference_table ADD CONSTRAINT fk FOREIGN KEY(referencing_column) REFERENCES referenced_local_table(id);
ERROR: cannot create foreign key constraint ERROR: cannot ADD/DROP foreign key constraint
DETAIL: Referenced table must be a distributed table or a reference table. DETAIL: Referenced table must be a distributed table or a reference table or a local table in coordinator.
HINT: To ADD/DROP foreign constraint between reference tables and coordinator local tables, consider adding coordinator to pg_dist_node as well.
-- test foreign key creation on ALTER TABLE on self referencing reference table -- test foreign key creation on ALTER TABLE on self referencing reference table
DROP TABLE self_referencing_reference_table; DROP TABLE self_referencing_reference_table;
CREATE TABLE self_referencing_reference_table( CREATE TABLE self_referencing_reference_table(

View File

@ -661,6 +661,12 @@ CREATE TABLE ref_table_3(id int primary key, v int references ref_table_2(id));
SELECT create_reference_table('ref_table_1'), SELECT create_reference_table('ref_table_1'),
create_reference_table('ref_table_2'), create_reference_table('ref_table_2'),
create_reference_table('ref_table_3'); create_reference_table('ref_table_3');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table | create_reference_table | create_reference_table create_reference_table | create_reference_table | create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
| | | |

View File

@ -30,12 +30,18 @@ CREATE TABLE referencing_table(id int, ref_id int);
ALTER TABLE referencing_table ADD CONSTRAINT fkey_ref FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE; ALTER TABLE referencing_table ADD CONSTRAINT fkey_ref FOREIGN KEY (id) REFERENCES referenced_table(test_column) ON DELETE CASCADE;
ALTER TABLE referencing_table ADD CONSTRAINT foreign_key_2 FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE; ALTER TABLE referencing_table ADD CONSTRAINT foreign_key_2 FOREIGN KEY (id) REFERENCES referenced_table2(test_column2) ON DELETE CASCADE;
SELECT create_reference_table('referenced_table'); SELECT create_reference_table('referenced_table');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------
(1 row) (1 row)
SELECT create_reference_table('referenced_table2'); SELECT create_reference_table('referenced_table2');
WARNING: should not create foreign key constraint in this way
DETAIL: Local table referenced by another local table should not be upgraded to a reference table
HINT: To define foreign key constraint from a local table to a reference table properly, use ALTER TABLE ADD CONSTRAINT ... command after creating the reference table without a foreign key
create_reference_table create_reference_table
--------------------------------------------------------------------- ---------------------------------------------------------------------