@@ -822,12 +822,12 @@ INSERT INTO PKTABLE VALUES(42);
822822-- This next should fail, because int=inet does not exist
823823CREATE TABLE FKTABLE (ftest1 inet REFERENCES pktable);
824824ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented
825- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: inet and integer.
825+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
826826-- This should also fail for the same reason, but here we
827827-- give the column name
828828CREATE TABLE FKTABLE (ftest1 inet REFERENCES pktable(ptest1));
829829ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented
830- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: inet and integer.
830+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
831831-- This should succeed, even though they are different types,
832832-- because int=int8 exists and is a member of the integer opfamily
833833CREATE TABLE FKTABLE (ftest1 int8 REFERENCES pktable);
@@ -846,7 +846,7 @@ DROP TABLE FKTABLE;
846846-- of the integer opfamily)
847847CREATE TABLE FKTABLE (ftest1 numeric REFERENCES pktable);
848848ERROR: foreign key constraint "fktable_ftest1_fkey" cannot be implemented
849- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: numeric and integer.
849+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: numeric and integer.
850850DROP TABLE PKTABLE;
851851-- On the other hand, this should work because int implicitly promotes to
852852-- numeric, and we allow promotion on the FK side
@@ -869,23 +869,23 @@ CREATE TABLE PKTABLE (ptest1 int, ptest2 inet, PRIMARY KEY(ptest1, ptest2));
869869-- This should fail, because we just chose really odd types
870870CREATE TABLE FKTABLE (ftest1 cidr, ftest2 timestamp, FOREIGN KEY(ftest1, ftest2) REFERENCES pktable);
871871ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
872- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: cidr and integer.
872+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: cidr and integer.
873873-- Again, so should this...
874874CREATE TABLE FKTABLE (ftest1 cidr, ftest2 timestamp, FOREIGN KEY(ftest1, ftest2) REFERENCES pktable(ptest1, ptest2));
875875ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
876- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: cidr and integer.
876+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: cidr and integer.
877877-- This fails because we mixed up the column ordering
878878CREATE TABLE FKTABLE (ftest1 int, ftest2 inet, FOREIGN KEY(ftest2, ftest1) REFERENCES pktable);
879879ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
880- DETAIL: Key columns "ftest2" and "ptest1" are of incompatible types: inet and integer.
880+ DETAIL: Key columns "ftest2" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
881881-- As does this...
882882CREATE TABLE FKTABLE (ftest1 int, ftest2 inet, FOREIGN KEY(ftest2, ftest1) REFERENCES pktable(ptest1, ptest2));
883883ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
884- DETAIL: Key columns "ftest2" and "ptest1" are of incompatible types: inet and integer.
884+ DETAIL: Key columns "ftest2" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
885885-- And again..
886886CREATE TABLE FKTABLE (ftest1 int, ftest2 inet, FOREIGN KEY(ftest1, ftest2) REFERENCES pktable(ptest2, ptest1));
887887ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
888- DETAIL: Key columns "ftest1" and "ptest2" are of incompatible types: integer and inet.
888+ DETAIL: Key columns "ftest1" of the referencing table and "ptest2" of the referenced table are of incompatible types: integer and inet.
889889-- This works...
890890CREATE TABLE FKTABLE (ftest1 int, ftest2 inet, FOREIGN KEY(ftest2, ftest1) REFERENCES pktable(ptest2, ptest1));
891891DROP TABLE FKTABLE;
@@ -906,17 +906,17 @@ DROP TABLE PKTABLE;
906906CREATE TABLE PKTABLE (ptest1 int, ptest2 inet, ptest3 int, ptest4 inet, PRIMARY KEY(ptest1, ptest2), FOREIGN KEY(ptest3,
907907ptest4) REFERENCES pktable(ptest2, ptest1));
908908ERROR: foreign key constraint "pktable_ptest3_ptest4_fkey" cannot be implemented
909- DETAIL: Key columns "ptest3" and "ptest2" are of incompatible types: integer and inet.
909+ DETAIL: Key columns "ptest3" of the referencing table and "ptest2" of the referenced table are of incompatible types: integer and inet.
910910-- Nor should this... (same reason, we have 4,3 referencing 1,2 which mismatches types
911911CREATE TABLE PKTABLE (ptest1 int, ptest2 inet, ptest3 int, ptest4 inet, PRIMARY KEY(ptest1, ptest2), FOREIGN KEY(ptest4,
912912ptest3) REFERENCES pktable(ptest1, ptest2));
913913ERROR: foreign key constraint "pktable_ptest4_ptest3_fkey" cannot be implemented
914- DETAIL: Key columns "ptest4" and "ptest1" are of incompatible types: inet and integer.
914+ DETAIL: Key columns "ptest4" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
915915-- Not this one either... Same as the last one except we didn't defined the columns being referenced.
916916CREATE TABLE PKTABLE (ptest1 int, ptest2 inet, ptest3 int, ptest4 inet, PRIMARY KEY(ptest1, ptest2), FOREIGN KEY(ptest4,
917917ptest3) REFERENCES pktable);
918918ERROR: foreign key constraint "pktable_ptest4_ptest3_fkey" cannot be implemented
919- DETAIL: Key columns "ptest4" and "ptest1" are of incompatible types: inet and integer.
919+ DETAIL: Key columns "ptest4" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet and integer.
920920--
921921-- Now some cases with inheritance
922922-- Basic 2 table case: 1 column of matching types.
@@ -1009,40 +1009,40 @@ create table pktable(ptest1 inet, primary key(base1, ptest1)) inherits (pktable_
10091009-- just generally bad types (with and without column references on the referenced table)
10101010create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable);
10111011ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
1012- DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer.
1012+ DETAIL: Key columns "ftest1" of the referencing table and "base1" of the referenced table are of incompatible types: cidr and integer.
10131013create table fktable(ftest1 cidr, ftest2 int[], foreign key (ftest1, ftest2) references pktable(base1, ptest1));
10141014ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
1015- DETAIL: Key columns "ftest1" and "base1" are of incompatible types: cidr and integer.
1015+ DETAIL: Key columns "ftest1" of the referencing table and "base1" of the referenced table are of incompatible types: cidr and integer.
10161016-- let's mix up which columns reference which
10171017create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable);
10181018ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
1019- DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer.
1019+ DETAIL: Key columns "ftest2" of the referencing table and "base1" of the referenced table are of incompatible types: inet and integer.
10201020create table fktable(ftest1 int, ftest2 inet, foreign key(ftest2, ftest1) references pktable(base1, ptest1));
10211021ERROR: foreign key constraint "fktable_ftest2_ftest1_fkey" cannot be implemented
1022- DETAIL: Key columns "ftest2" and "base1" are of incompatible types: inet and integer.
1022+ DETAIL: Key columns "ftest2" of the referencing table and "base1" of the referenced table are of incompatible types: inet and integer.
10231023create table fktable(ftest1 int, ftest2 inet, foreign key(ftest1, ftest2) references pktable(ptest1, base1));
10241024ERROR: foreign key constraint "fktable_ftest1_ftest2_fkey" cannot be implemented
1025- DETAIL: Key columns "ftest1" and "ptest1" are of incompatible types: integer and inet.
1025+ DETAIL: Key columns "ftest1" of the referencing table and "ptest1" of the referenced table are of incompatible types: integer and inet.
10261026drop table pktable;
10271027drop table pktable_base;
10281028-- 2 columns (1 table), mismatched types
10291029create table pktable_base(base1 int not null, base2 int);
10301030create table pktable(ptest1 inet, ptest2 inet[], primary key(base1, ptest1), foreign key(base2, ptest2) references
10311031 pktable(base1, ptest1)) inherits (pktable_base);
10321032ERROR: foreign key constraint "pktable_base2_ptest2_fkey" cannot be implemented
1033- DETAIL: Key columns "ptest2" and "ptest1" are of incompatible types: inet[] and inet.
1033+ DETAIL: Key columns "ptest2" of the referencing table and "ptest1" of the referenced table are of incompatible types: inet[] and inet.
10341034create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(base2, ptest2) references
10351035 pktable(ptest1, base1)) inherits (pktable_base);
10361036ERROR: foreign key constraint "pktable_base2_ptest2_fkey" cannot be implemented
1037- DETAIL: Key columns "base2" and "ptest1" are of incompatible types: integer and inet.
1037+ DETAIL: Key columns "base2" of the referencing table and "ptest1" of the referenced table are of incompatible types: integer and inet.
10381038create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references
10391039 pktable(base1, ptest1)) inherits (pktable_base);
10401040ERROR: foreign key constraint "pktable_ptest2_base2_fkey" cannot be implemented
1041- DETAIL: Key columns "ptest2" and "base1" are of incompatible types: inet and integer.
1041+ DETAIL: Key columns "ptest2" of the referencing table and "base1" of the referenced table are of incompatible types: inet and integer.
10421042create table pktable(ptest1 inet, ptest2 inet, primary key(base1, ptest1), foreign key(ptest2, base2) references
10431043 pktable(base1, ptest1)) inherits (pktable_base);
10441044ERROR: foreign key constraint "pktable_ptest2_base2_fkey" cannot be implemented
1045- DETAIL: Key columns "ptest2" and "base1" are of incompatible types: inet and integer.
1045+ DETAIL: Key columns "ptest2" of the referencing table and "base1" of the referenced table are of incompatible types: inet and integer.
10461046drop table pktable;
10471047ERROR: table "pktable" does not exist
10481048drop table pktable_base;
@@ -1154,22 +1154,22 @@ CREATE TEMP TABLE fktable (
11541154ALTER TABLE fktable ADD CONSTRAINT fk_2_3
11551155FOREIGN KEY (x2) REFERENCES pktable(id3);
11561156ERROR: foreign key constraint "fk_2_3" cannot be implemented
1157- DETAIL: Key columns "x2" and "id3" are of incompatible types: character varying and real.
1157+ DETAIL: Key columns "x2" of the referencing table and "id3" of the referenced table are of incompatible types: character varying and real.
11581158-- nor to int4
11591159ALTER TABLE fktable ADD CONSTRAINT fk_2_1
11601160FOREIGN KEY (x2) REFERENCES pktable(id1);
11611161ERROR: foreign key constraint "fk_2_1" cannot be implemented
1162- DETAIL: Key columns "x2" and "id1" are of incompatible types: character varying and integer.
1162+ DETAIL: Key columns "x2" of the referencing table and "id1" of the referenced table are of incompatible types: character varying and integer.
11631163-- real does not promote to int4
11641164ALTER TABLE fktable ADD CONSTRAINT fk_3_1
11651165FOREIGN KEY (x3) REFERENCES pktable(id1);
11661166ERROR: foreign key constraint "fk_3_1" cannot be implemented
1167- DETAIL: Key columns "x3" and "id1" are of incompatible types: real and integer.
1167+ DETAIL: Key columns "x3" of the referencing table and "id1" of the referenced table are of incompatible types: real and integer.
11681168-- int4 does not promote to text
11691169ALTER TABLE fktable ADD CONSTRAINT fk_1_2
11701170FOREIGN KEY (x1) REFERENCES pktable(id2);
11711171ERROR: foreign key constraint "fk_1_2" cannot be implemented
1172- DETAIL: Key columns "x1" and "id2" are of incompatible types: integer and character varying.
1172+ DETAIL: Key columns "x1" of the referencing table and "id2" of the referenced table are of incompatible types: integer and character varying.
11731173-- should succeed
11741174-- int4 promotes to real
11751175ALTER TABLE fktable ADD CONSTRAINT fk_1_3
@@ -1192,11 +1192,11 @@ FOREIGN KEY (x2,x5,x3) REFERENCES pktable(id2,id1,id3);
11921192ALTER TABLE fktable ADD CONSTRAINT fk_123_231
11931193FOREIGN KEY (x1,x2,x3) REFERENCES pktable(id2,id3,id1);
11941194ERROR: foreign key constraint "fk_123_231" cannot be implemented
1195- DETAIL: Key columns "x1" and "id2" are of incompatible types: integer and character varying.
1195+ DETAIL: Key columns "x1" of the referencing table and "id2" of the referenced table are of incompatible types: integer and character varying.
11961196ALTER TABLE fktable ADD CONSTRAINT fk_241_132
11971197FOREIGN KEY (x2,x4,x1) REFERENCES pktable(id1,id3,id2);
11981198ERROR: foreign key constraint "fk_241_132" cannot be implemented
1199- DETAIL: Key columns "x2" and "id1" are of incompatible types: character varying and integer.
1199+ DETAIL: Key columns "x2" of the referencing table and "id1" of the referenced table are of incompatible types: character varying and integer.
12001200DROP TABLE pktable, fktable;
12011201-- test a tricky case: we can elide firing the FK check trigger during
12021202-- an UPDATE if the UPDATE did not change the foreign key
0 commit comments