ERROR: insert or update on table "fp_fk_order" violates foreign key constraint "fp_fk_order_a_c_b_fkey"
DETAIL: Key (a, c, b)=(9, 99, none) is not present in table "fp_pk_order".
DROP TABLE fp_fk_order, fp_pk_order;
+-- Same-type columns in different order:
+CREATE TABLE fp_pk_same (c1 int, c2 int, PRIMARY KEY (c1, c2));
+INSERT INTO fp_pk_same VALUES (1, 2);
+CREATE TABLE fp_fk_same (c1 int, c2 int,
+ FOREIGN KEY (c2, c1) REFERENCES fp_pk_same (c2, c1));
+INSERT INTO fp_fk_same VALUES (1, 2); -- should succeed
+INSERT INTO fp_fk_same VALUES (9, 9); -- should fail
+ERROR: insert or update on table "fp_fk_same" violates foreign key constraint "fp_fk_same_c2_c1_fkey"
+DETAIL: Key (c2, c1)=(9, 9) is not present in table "fp_pk_same".
+DROP TABLE fp_fk_same, fp_pk_same;
-- Deferred constraint: batch flushed at COMMIT, not at statement end
CREATE TABLE fp_pk_commit (a int PRIMARY KEY);
CREATE TABLE fp_fk_commit (a int REFERENCES fp_pk_commit
INSERT INTO fp_fk_order VALUES (3, 99, 'none', 9); -- should fail
DROP TABLE fp_fk_order, fp_pk_order;
+-- Same-type columns in different order:
+CREATE TABLE fp_pk_same (c1 int, c2 int, PRIMARY KEY (c1, c2));
+INSERT INTO fp_pk_same VALUES (1, 2);
+CREATE TABLE fp_fk_same (c1 int, c2 int,
+ FOREIGN KEY (c2, c1) REFERENCES fp_pk_same (c2, c1));
+INSERT INTO fp_fk_same VALUES (1, 2); -- should succeed
+INSERT INTO fp_fk_same VALUES (9, 9); -- should fail
+DROP TABLE fp_fk_same, fp_pk_same;
+
-- Deferred constraint: batch flushed at COMMIT, not at statement end
CREATE TABLE fp_pk_commit (a int PRIMARY KEY);
CREATE TABLE fp_fk_commit (a int REFERENCES fp_pk_commit