8000 Change the names generated for child foreign key constraints. · petergeoghegan/postgres@3db61db · GitHub
[go: up one dir, main page]

Skip to content

Commit 3db61db

Browse files
committed
Change the names generated for child foreign key constraints.
When a foreign key constraint is placed on a partitioned table, we actually make two pg_constraint entries associated with that table. (I have my doubts about the wisdom of that, but it's been like that since v12 and post-feature-freeze is no time to be messing with such entrenched decisions.) The second "child" entry always had a name generated according to the default rule, "table_column(s)_fkey[nnn]", even if the primary entry had an unrelated user-specified name. The trouble with doing that is that the default name could collide with the user-specified name of some other constraint on the same table. While we were willing to adjust the generated name to avoid collisions, that only helps if it's made second; if it's made first then creation of the other constraint would fail, potentially causing dump/reload or pg_upgrade failures. The core of the problem here is that we're infringing on user namespace, so I doubt that there's any 100% solution other than to find a way to not need the "child" entry. In the meantime, it seems like it'd be an improvement to make the child's name be the name of the parent constraint with an underscore and digit(s) appended as necessary to make it unique. This rule can in theory fail in the same way, but it seems much less probable; for one thing, this rule is guaranteed not to match primary entries having auto-generated names. (While an auto-generated primary name isn't user-specified to begin with, it acts like that during dump/reload, so collisions against such names are definitely possible.) An additional bonus, visible in some of the regression test cases that change here, arises from the fact that some error messages cite the child constraint's name not the parent's. In the previous approach the two names could be completely unrelated, leading to user confusion --- the more so since psql's \d command hides child constraints. With this approach it's hopefully much clearer which constraint-the-user-knows-about is failing. However, that does mean that there's user-visible behavior change occurring here, making it seem like not something to back-patch. I feel it's not too late for v18, though. Reported-by: Kirill Reshke <reshkekirill@gmail.com> Author: Tom Lane <tgl@sss.pgh.pa.us> Reviewed-by: Alvaro Herrera <alvherre@kurilemu.de> Discussion: https://postgr.es/m/CALdSSPhGitjpTfzEMJN-Y2x+Q-5QChSxAsmSJ1-E8mQJLkHOqQ@mail.gmail.com
1 parent 994a100 commit 3db61db

File tree

10 files changed

+74
-67
lines changed

10 files changed

+74
-67
lines changed

src/backend/catalog/pg_constraint.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,8 @@ ConstraintNameExists(const char *conname, Oid namespaceid)
495495
* name1, name2, and label are used the same way as for makeObjectName(),
496496
* except that the label can't be NULL; digits will be appended to the label
497497
* if needed to create a name that is unique within the specified namespace.
498+
* If the given label is empty, we only consider names that include at least
499+
* one added digit.
498500
*
499501
* 'others' can be a list of string names already chosen within the current
500502
* command (but not yet reflected into the catalogs); we will not choose
@@ -523,8 +525,11 @@ ChooseConstraintName(const char *name1, const char *name2,
523525

524526
conDesc = table_open(ConstraintRelationId, AccessShareLock);
525527

526-
/* try the unmodified label first */
527-
strlcpy(modlabel, label, sizeof(modlabel));
528+
/* try the unmodified label first, unless it's empty */
529+
if (label[0] != '\0')
530+
strlcpy(modlabel, label, sizeof(modlabel));
531+
else
532+
snprintf(modlabel, sizeof(modlabel), "%s%d", label, ++pass);
528533

529534
for (;;)
530535
{

src/backend/commands/tablecmds.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10712,14 +10712,16 @@ addFkConstraint(addFkConstraintSides fkside,
1071210712

1071310713
/*
1071410714
* Caller supplies us with a constraint name; however, it may be used in
10715-
* this partition, so come up with a different one in that case.
10715+
* this partition, so come up with a different one in that case. Unless
10716+
* truncation to NAMEDATALEN dictates otherwise, the new name will be the
10717+
* supplied name with an underscore and digit(s) appended.
1071610718
*/
1071710719
if (ConstraintNameIsUsed(CONSTRAINT_RELATION,
1071810720
RelationGetRelid(rel),
1071910721
constraintname))
10720-
conname = ChooseConstraintName(RelationGetRelationName(rel),
10721-
ChooseForeignKeyConstraintNameAddition(fkconstraint->fk_attrs),
10722-
"fkey",
10722+
conname = ChooseConstraintName(constraintname,
10723+
NULL,
10724+
"",
1072310725
RelationGetNamespace(rel), NIL);
1072410726
else
1072510727
conname = constraintname;

src/test/isolation/expected/detach-partition-concurrently-2.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ a
4141

4242
step s3i1: INSERT INTO d_lp_fk_r VALUES (1);
4343
step s2d: ALTER TABLE d_lp_fk DETACH PARTITION d_lp_fk_1 CONCURRENTLY;
44-
ERROR: removing partition "d_lp_fk_1" violates foreign key constraint "d_lp_fk_r_a_fkey1"
44+
ERROR: removing partition "d_lp_fk_1" violates foreign key constraint "d_lp_fk_r_a_fkey_1"
4545
step s1c: COMMIT;
4646

4747
starting permutation: s1b s1s s3i2 s2d s1c

src/test/isolation/expected/detach-partition-concurrently-4.out

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ step s1updcur: update d4_fk set a = 1 where current of f;
298298
step s2detach: alter table d4_primary detach partition d4_primary1 concurrently; <waiting ...>
299299
step s1c: commit;
300300
step s2detach: <... completed>
301-
ERROR: removing partition "d4_primary1" violates foreign key constraint "d4_fk_a_fkey1"
301+
ERROR: removing partition "d4_primary1" violates foreign key constraint "d4_fk_a_fkey_1"
302302

303303
starting permutation: s2snitch s1b s1s s2detach s3insert s1c
304304
step s2snitch: insert into d4_pid select pg_backend_pid();

src/test/isolation/expected/fk-partitioned-1.out

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
5454
step s1d: delete from ppk1 where a = 1; <waiting ...>
5555
step s2c: commit;
5656
step s1d: <... completed>
57-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
57+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
5858
step s1c: commit;
5959

6060
starting permutation: s1b s2b s2a s2c s1d s1c
@@ -63,7 +63,7 @@ step s2b: begin;
6363
step s2a: alter table pfk attach partition pfk1 for values in (1);
6464
step s2c: commit;
6565
step s1d: delete from ppk1 where a = 1;
66-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
66+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
6767
step s1c: commit;
6868

6969
starting permutation: s2b s1b s1d s1c s2a s2c
@@ -92,7 +92,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
9292
step s1d: delete from ppk1 where a = 1; <waiting ...>
9393
step s2c: commit;
9494
step s1d: <... completed>
95-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
95+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
9696
step s1c: commit;
9797

9898
starting permutation: s2b s1b s2a s2c s1d s1c
@@ -101,7 +101,7 @@ step s1b: begin;
101101
step s2a: alter table pfk attach partition pfk1 for values in (1);
102102
step s2c: commit;
103103
step s1d: delete from ppk1 where a = 1;
104-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
104+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
105105
step s1c: commit;
106106

107107
starting permutation: s2b s2a s1b s1d s2c s1c
@@ -111,7 +111,7 @@ step s1b: begin;
111111
step s1d: delete from ppk1 where a = 1; <waiting ...>
112112
step s2c: commit;
113113
step s1d: <... completed>
114-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
114+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
115115
step s1c: commit;
116116

117117
starting permutation: s2b s2a s1b s2c s1d s1c
@@ -120,7 +120,7 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
120120
step s1b: begin;
121121
step s2c: commit;
122122
step s1d: delete from ppk1 where a = 1;
123-
ERROR: update or delete on table "ppk1&quo 10000 t; violates foreign key constraint "pfk_a_fkey1" on table "pfk"
123+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
124124
step s1c: commit;
125125

126126
starting permutation: s2b s2a s2c s1b s1d s1c
@@ -129,5 +129,5 @@ step s2a: alter table pfk attach partition pfk1 for values in (1);
129129
step s2c: commit;
130130
step s1b: begin;
131131
step s1d: delete from ppk1 where a = 1;
132-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
132+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
133133
step s1c: commit;

src/test/isolation/expected/fk-partitioned-2.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ step s2i: insert into pfk values (1);
5757
step s1d: delete from ppk where a = 1; <waiting ...>
5858
step s2c: commit;
5959
step s1d: <... completed>
60-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
60+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
6161
step s1c: commit;
6262

6363
starting permutation: s1b s2bs s2i s1d s2c s1c
@@ -72,5 +72,5 @@ step s2i: insert into pfk values (1);
7272
step s1d: delete from ppk where a = 1; <waiting ...>
7373
step s2c: commit;
7474
step s1d: <... completed>
75-
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey1" on table "pfk"
75+
ERROR: update or delete on table "ppk1" violates foreign key constraint "pfk_a_fkey_1" on table "pfk"
7676
step s1c: commit;

src/test/regress/expected/constraints.out

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -641,9 +641,9 @@ CREATE TABLE parted_fk_naming_1 (
641641
);
642642
ALTER TABLE parted_fk_naming ATTACH PARTITION parted_fk_naming_1 FOR VALUES IN ('1');
643643
SELECT conname FROM pg_constraint WHERE conrelid = 'parted_fk_naming_1'::regclass AND contype = 'f';
644-
conname
645-
--------------------------------
646-
parted_fk_naming_1_id_abc_fkey
644+
conname
645+
----------------
646+
dummy_constr_1
647647
(1 row)
648648

649649
DROP TABLE parted_fk_naming;

src/test/regress/expected/foreign_key.out

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1903,20 +1903,20 @@ ALTER TABLE fk_notpartitioned_fk ADD FOREIGN KEY (a, b) REFERENCES fk_partitione
19031903
-- Constraint will be invalid.
19041904
SELECT conname, convalidated FROM pg_constraint
19051905
WHERE conrelid = 'fk_notpartitioned_fk'::regclass ORDER BY oid::regclass::text;
1906-
conname | convalidated
1907-
--------------------------------+--------------
1908-
fk_notpartitioned_fk_a_b_fkey | f
1909-
fk_notpartitioned_fk_a_b_fkey1 | f
1906+
conname | convalidated
1907+
---------------------------------+--------------
1908+
fk_notpartitioned_fk_a_b_fkey | f
1909+
fk_notpartitioned_fk_a_b_fkey_1 | f
19101910
(2 rows)
19111911

19121912
ALTER TABLE fk_notpartitioned_fk VALIDATE CONSTRAINT fk_notpartitioned_fk_a_b_fkey;
19131913
-- All constraints are now valid.
19141914
SELECT conname, convalidated FROM pg_constraint
19151915
WHERE conrelid = 'fk_notpartitioned_fk'::regclass ORDER BY oid::regclass::text;
1916-
conname | convalidated
1917-
--------------------------------+--------------
1918-
fk_notpartitioned_fk_a_b_fkey | t
1919-
fk_notpartitioned_fk_a_b_fkey1 | t
1916+
conname | convalidated
1917+
---------------------------------+--------------
1918+
fk_notpartitioned_fk_a_b_fkey | t
1919+
fk_notpartitioned_fk_a_b_fkey_1 | t
19201920
(2 rows)
19211921

19221922
DROP TABLE fk_notpartitioned_fk, fk_partitioned_pk;
@@ -2589,40 +2589,40 @@ INSERT into pk VALUES (1), (1000), (2000), (3000), (4000), (4500);
25892589
INSERT into fk VALUES (1), (1000), (2000), (3000), (4000), (4500);
25902590
-- should fail: referencing value present
25912591
DELETE FROM pk WHERE a = 1;
2592-
ERROR: update or delete on table "pk1" violates foreign key constraint "fk_a_fkey1" on table "fk"
2592+
ERROR: update or delete on table "pk1" violates foreign key constraint "fk_a_fkey_1" on table "fk"
25932593
DETAIL: Key (a)=(1) is still referenced from table "fk".
25942594
DELETE FROM pk WHERE a = 1000;
2595-
ERROR: update or delete on table "pk2" violates foreign key constraint "fk_a_fkey2" on table "fk"
2595+
ERROR: update or delete on table "pk2" violates foreign key constraint "fk_a_fkey_2" on table "fk"
25962596
DETAIL: Key (a)=(1000) is still referenced from table "fk".
25972597
DELETE FROM pk WHERE a = 2000;
2598-
ERROR: update or delete on table "pk3" violates foreign key constraint "fk_a_fkey3" on table "fk"
2598+
ERROR: update or delete on table "pk3" violates foreign key constraint "fk_a_fkey_3" on table "fk"
25992599
DETAIL: Key (a)=(2000) is still referenced from table "fk".
26002600
DELETE FROM pk WHERE a = 3000;
2601-
ERROR: update or delete on table "pk4" violates foreign key constraint "fk_a_fkey4" on table "fk"
2601+
ERROR: update or delete on table "pk4" violates foreign key constraint "fk_a_fkey_4" on table "fk"
26022602
DETAIL: Key (a)=(3000) is still referenced from table "fk".
26032603
DELETE FROM pk WHERE a = 4000;
2604-
ERROR: update or delete on table "pk51" violates foreign key constraint "fk_a_fkey6" on table "fk"
2604+
ERROR: update or delete on table "pk51" violates foreign key constraint "fk_a_fkey_6" on table "fk"
26052605
DETAIL: Key (a)=(4000) is still referenced from table "fk".
26062606
DELETE FROM pk WHERE a = 4500;
2607-
ERROR: update or delete on table "pk52" violates foreign key constraint "fk_a_fkey7" on table "fk"
2607+
ERROR: update or delete on table "pk52" violates foreign key constraint "fk_a_fkey_7" on table "fk"
26082608
DETAIL: Key (a)=(4500) is still referenced from table "fk".
26092609
UPDATE pk SET a = 2 WHERE a = 1;
2610-
ERROR: update or delete on table "pk1" violates foreign key constraint "fk_a_fkey1" on table "fk"
2610+
ERROR: update or delete on table "pk1" violates foreign key constraint "fk_a_fkey_1" on table "fk"
26112611
DETAIL: Key (a)=(1) is still referenced from table "fk".
26122612
UPDATE pk SET a = 1002 WHERE a = 1000;
2613-
ERROR: update or delete on table "pk2" violates foreign key constraint "fk_a_fkey2" on table "fk"
2613+
ERROR: update or delete on table "pk2" violates foreign key constraint "fk_a_fkey_2" on table "fk"
26142614
DETAIL: Key (a)=(1000) is still referenced from table "fk".
26152615
UPDATE pk SET a = 2002 WHERE a = 2000;
2616-
ERROR: update or delete on table "pk3" violates foreign key constraint "fk_a_fkey3" on table "fk"
2616+
ERROR: update or delete on table "pk3" violates foreign key constraint "fk_a_fkey_3" on table "fk"
26172617
DETAIL: Key (a)=(2000) is still referenced from table "fk".
26182618
UPDATE pk SET a = 3002 WHERE a = 3000;
2619-
ERROR: update or delete on table "pk4" violates foreign key constraint "fk_a_fkey4" on table "fk"
2619+
ERROR: update or delete on table "pk4" violates foreign key constraint "fk_a_fkey_4" on table "fk"
26202620
DETAIL: Key (a)=(3000) is still referenced from table "fk".
26212621
UPDATE pk SET a = 4002 WHERE a = 4000;
2622-
ERROR: update or delete on table "pk51" violates foreign key constraint "fk_a_fkey6" on table "fk"
2622+
ERROR: update or delete on table "pk51" violates foreign key constraint "fk_a_fkey_6" on table "fk"
26232623
DETAIL: Key (a)=(4000) is still referenced from table "fk".
26242624
UPDATE pk SET a = 4502 WHERE a = 4500;
2625-
ERROR: update or delete on table "pk52" violates foreign key constraint "fk_a_fkey7" on table "fk"
2625+
ERROR: update or delete on table "pk52" violates foreign key constraint "fk_a_fkey_7" on table "fk"
26262626
DETAIL: Key (a)=(4500) is still referenced from table "fk".
26272627
-- now they should work
26282628
DELETE FROM fk;
@@ -2661,19 +2661,19 @@ CREATE TABLE dropfk (a int REFERENCES droppk);
26612661
INSERT into dropfk VALUES (1), (1000), (1500), (2000);
26622662
-- these should all fail
26632663
ALTER TABLE droppk DETACH PARTITION droppk_d;
2664-
ERROR: removing partition "droppk_d" violates foreign key constraint "dropfk_a_fkey5"
2664+
ERROR: removing partition "droppk_d" violates foreign key constraint "dropfk_a_fkey_5"
26652665
DETAIL: Key (a)=(2000) is still referenced from table "dropfk".
26662666
ALTER TABLE droppk2 DETACH PARTITION droppk2_d;
2667-
ERROR: removing partition "droppk2_d" violates foreign key constraint "dropfk_a_fkey4"
2667+
ERROR: removing partition "droppk2_d" violates foreign key constraint "dropfk_a_fkey_4"
26682668
DETAIL: Key (a)=(1500) is still referenced from table "dropfk".
26692669
ALTER TABLE droppk DETACH PARTITION droppk1;
2670-
ERROR: removing partition "droppk1" violates foreign key constraint "dropfk_a_fkey1"
2670+
ERROR: removing partition "droppk1" violates foreign key constraint "dropfk_a_fkey_1"
26712671
DETAIL: Key (a)=(1) is still referenced from table "dropfk".
26722672
ALTER TABLE droppk DETACH PARTITION droppk2;
2673-
ERROR: removing partition "droppk2" violates foreign key constraint "dropfk_a_fkey2"
2673+
ERROR: removing partition "droppk2" violates foreign key constraint "dropfk_a_fkey_2"
26742674
DETAIL: Key (a)=(1000) is still referenced from table "dropfk".
26752675
ALTER TABLE droppk2 DETACH PARTITION droppk21;
2676-
ERROR: removing partition "droppk21" violates foreign key constraint "dropfk_a_fkey3"
2676+
ERROR: removing partition "droppk21" violates foreign key constraint "dropfk_a_fkey_3"
26772677
DETAIL: Key (a)=(1000) is still referenced from table "dropfk".
26782678
-- dropping partitions is disallowed
26792679
DROP TABLE droppk_d;
@@ -2742,15 +2742,15 @@ SELECT pg_describe_object('pg_constraint'::regclass, oid, 0), confrelid::regclas
27422742
FROM pg_catalog.pg_constraint
27432743
WHERE conrelid IN (SELECT relid FROM pg_partition_tree('fk'))
27442744
ORDER BY conrelid::regclass::text, conname;
2745-
pg_describe_object | confrelid | case
2746-
------------------------------------+-----------+-----------------------------------
2745+
pg_describe_object | confrelid | case
2746+
------------------------------------+-----------+------------------------------------
27472747
constraint fk_a_fkey on table fk | pk | TOP
2748-
constraint fk_a_fkey1 on table fk | pk1 | constraint fk_a_fkey on table fk
2749-
constraint fk_a_fkey2 on table fk | pk11 | constraint fk_a_fkey1 on table fk
2750-
constraint fk_a_fkey3 on table fk | pk2 | constraint fk_a_fkey on table fk
2751-
constraint fk_a_fkey4 on table fk | pk3 | constraint fk_a_fkey on table fk
2752-
constraint fk_a_fkey5 on table fk | pk31 | constraint fk_a_fkey4 on table fk
2753-
constraint fk_a_fkey6 on table fk | pk32 | constraint fk_a_fkey4 on table fk
2748+
constraint fk_a_fkey_1 on table fk | pk1 | constraint fk_a_fkey on table fk
2749+
constraint fk_a_fkey_2 on table fk | pk11 | constraint fk_a_fkey_1 on table fk
2750+
constraint fk_a_fkey_3 on table fk | pk2 | constraint fk_a_fkey on table fk
2751+
constraint fk_a_fkey_4 on table fk | pk3 | constraint fk_a_fkey on table fk
2752+
constraint fk_a_fkey_5 on table fk | pk31 | constraint fk_a_fkey_4 on table fk
2753+
constraint fk_a_fkey_6 on table fk | pk32 | constraint fk_a_fkey_4 on table fk
27542754
constraint fk_a_fkey on table fk1 | pk | constraint fk_a_fkey on table fk
27552755
constraint fk_a_fkey on table fk11 | pk | constraint fk_a_fkey on table fk1
27562756
constraint fk_a_fkey on table fk2 | pk | constraint fk_a_fkey on table fk
@@ -2853,10 +2853,10 @@ CREATE TABLE pt1 PARTITION OF pt1_2 FOR VALUES IN (1);
28532853
CREATE TABLE pt2 PARTITION OF pt1_2 FOR VALUES IN (2);
28542854
CREATE TABLE ref(f1 int, f2 int, f3 int);
28552855
ALTER TABLE ref ADD FOREIGN KEY(f1,f2) REFERENCES pt;
2856-
ALTER TABLE ref ALTER CONSTRAINT ref_f1_f2_fkey1
2856+
ALTER TABLE ref ALTER CONSTRAINT ref_f1_f2_fkey_1
28572857
DEFERRABLE INITIALLY DEFERRED; -- fails
2858-
ERROR: cannot alter constraint "ref_f1_f2_fkey1" on relation "ref"
2859-
DETAIL: Constraint "ref_f1_f2_fkey1" is derived from constraint "ref_f1_f2_fkey" of relation "ref".
2858+
ERROR: cannot alter constraint "ref_f1_f2_fkey_1" on relation "ref"
2859+
DETAIL: Constraint "ref_f1_f2_fkey_1" is derived from constraint "ref_f1_f2_fkey" of relation "ref".
28602860
HINT: You may alter the constraint it derives from instead.
28612861
ALTER TABLE ref ALTER CONSTRAINT ref_f1_f2_fkey
28622862
DEFERRABLE INITIALLY DEFERRED;
@@ -2958,7 +2958,7 @@ ALTER TABLE fk ADD FOREIGN KEY (a) REFERENCES pk ON UPDATE RESTRICT ON DELETE RE
29582958
CREATE TABLE fk_d PARTITION OF fk DEFAULT;
29592959
INSERT INTO fk VALUES (20), (30);
29602960
DELETE FROM pk WHERE a = 20;
2961-
ERROR: update or delete on table "pk11" violates RESTRICT setting of foreign key constraint "fk_a_fkey2" on table "fk"
2961+
ERROR: update or delete on table "pk11" violates RESTRICT setting of foreign key constraint "fk_a_fkey_2" on table "fk"
29622962
DETAIL: Key (a)=(20) is referenced from table "fk".
29632963
UPDATE pk SET a = 90 WHERE a = 30;
29642964
ERROR: update or delete on table "pk" violates RESTRICT setting of foreign key constraint "fk_a_fkey" on table "fk"
@@ -3306,7 +3306,7 @@ INSERT INTO fk_r_1 (id, p_id, p_jd) VALUES (2, 1, 2); -- should fail
33063306
ERROR: insert or update on table "fk_r_1" violates foreign key constraint "fk_r_p_id_p_jd_fkey"
33073307
DETAIL: Key (p_id, p_jd)=(1, 2) is not present in table "fk_p".
33083308
DELETE FROM fk_p; -- should fail
3309-
ERROR: update or delete on table "fk_p_1_1" violates foreign key constraint "fk_r_1_p_id_p_jd_fkey1" on table "fk_r_1"
3309+
ERROR: update or delete on table "fk_p_1_1" violates foreign key constraint "fk_r_p_id_p_jd_fkey_7" on table "fk_r_1"
33103310
DETAIL: Key (id, jd)=(1, 1) is still referenced from table "fk_r_1".
33113311
ALTER TABLE fk_r ATTACH PARTITION fk_r_1 FOR VALUES IN (1);
33123312
ALTER TABLE fk_r ATTACH PARTITION fk_r_2 FOR VALUES IN (2);
@@ -3326,13 +3326,13 @@ Foreign-key constraints:
33263326
Number of partitions: 1 (Use \d+ to list them.)
33273327

33283328
DELETE FROM fk_p; -- should fail
3329-
ERROR: update or delete on table "fk_p_1_1" violates foreign key constraint "fk_r_p_id_p_jd_fkey2" on table "fk_r"
3329+
ERROR: update or delete on table "fk_p_1_1" violates foreign key constraint "fk_r_p_id_p_jd_fkey_2" on table "fk_r"
33303330
DETAIL: Key (id, jd)=(1, 1) is still referenced from table "fk_r".
33313331
-- these should all fail
33323332
ALTER TABLE fk_r_1 DROP CONSTRAINT fk_r_p_id_p_jd_fkey;
33333333
ERROR: cannot drop inherited constraint "fk_r_p_id_p_jd_fkey" of relation "fk_r_1"
3334-
ALTER TABLE fk_r DROP CONSTRAINT fk_r_p_id_p_jd_fkey1;
3335-
ERROR: cannot drop inherited constraint "fk_r_p_id_p_jd_fkey1" of relation "fk_r"
3334+
ALTER TABLE fk_r DROP CONSTRAINT fk_r_p_id_p_jd_fkey_1;
3335+
ERROR: cannot drop inherited constraint "fk_r_p_id_p_jd_fkey_1" of relation "fk_r"
33363336
ALTER TABLE fk_r_2 DROP CONSTRAINT fk_r_p_id_p_jd_fkey;
33373337
ERROR: cannot drop inherited constraint "fk_r_p_id_p_jd_fkey" of relation "fk_r_2"
33383338
SET client_min_messages TO warning;

0 commit comments

Comments
 (0)
0