Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit9c2a970

Browse files
committed
Improve two error messages related to foreign keys on partitioned tables
Error messages for creating a foreign key on a partitioned table usingONLY or NOT VALID were wrong in mentioning the objects they worked on.This commit adds on the way some regression tests missing for thosecases.Author: Laurenz AlbeReviewed-by: Michael PaquierDiscussion:https://postgr.es/m/c11c05810a9ed65e9b2c817a9ef442275a32fe80.camel@cybertec.at
1 parenta9da329 commit9c2a970

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

‎src/backend/commands/tablecmds.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7365,12 +7365,14 @@ ATAddForeignKeyConstraint(List **wqueue, AlteredTableInfo *tab, Relation rel,
73657365
if (!recurse)
73667366
ereport(ERROR,
73677367
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
7368-
errmsg("foreign key referencing partitioned table \"%s\" must not be ONLY",
7368+
errmsg("cannot use ONLY for foreign key on partitioned table \"%s\" referencing relation \"%s\"",
7369+
RelationGetRelationName(rel),
73697370
RelationGetRelationName(pkrel))));
73707371
if (fkconstraint->skip_validation&& !fkconstraint->initially_valid)
73717372
ereport(ERROR,
73727373
(errcode(ERRCODE_WRONG_OBJECT_TYPE),
7373-
errmsg("cannot add NOT VALID foreign key to relation \"%s\"",
7374+
errmsg("cannot add NOT VALID foreign key on partitioned table \"%s\" referencing relation \"%s\"",
7375+
RelationGetRelationName(rel),
73747376
RelationGetRelationName(pkrel)),
73757377
errdetail("This feature is not yet supported on partitioned tables.")));
73767378
}

‎src/test/regress/expected/foreign_key.out

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1465,6 +1465,17 @@ CREATE TABLE fk_partitioned_fk_3_0 PARTITION OF fk_partitioned_fk_3 FOR VALUES W
14651465
CREATE TABLE fk_partitioned_fk_3_1 PARTITION OF fk_partitioned_fk_3 FOR VALUES WITH (MODULUS 5, REMAINDER 1);
14661466
ALTER TABLE fk_partitioned_fk ATTACH PARTITION fk_partitioned_fk_3
14671467
FOR VALUES FROM (2000,2000) TO (3000,3000);
1468+
-- Creating a foreign key with ONLY on a partitioned table referencing
1469+
-- a non-partitioned table fails.
1470+
ALTER TABLE ONLY fk_partitioned_fk ADD FOREIGN KEY (a, b)
1471+
REFERENCES fk_notpartitioned_pk;
1472+
ERROR: cannot use ONLY for foreign key on partitioned table "fk_partitioned_fk" referencing relation "fk_notpartitioned_pk"
1473+
-- Adding a NOT VALID foreign key on a partitioned table referencing
1474+
-- a non-partitioned table fails.
1475+
ALTER TABLE fk_partitioned_fk ADD FOREIGN KEY (a, b)
1476+
REFERENCES fk_notpartitioned_pk NOT VALID;
1477+
ERROR: cannot add NOT VALID foreign key on partitioned table "fk_partitioned_fk" referencing relation "fk_notpartitioned_pk"
1478+
DETAIL: This feature is not yet supported on partitioned tables.
14681479
-- these inserts, targetting both the partition directly as well as the
14691480
-- partitioned table, should all fail
14701481
INSERT INTO fk_partitioned_fk (a,b) VALUES (500, 501);

‎src/test/regress/sql/foreign_key.sql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,6 +1106,15 @@ CREATE TABLE fk_partitioned_fk_3_1 PARTITION OF fk_partitioned_fk_3 FOR VALUES W
11061106
ALTERTABLE fk_partitioned_fk ATTACH PARTITION fk_partitioned_fk_3
11071107
FORVALUESFROM (2000,2000) TO (3000,3000);
11081108

1109+
-- Creating a foreign key with ONLY on a partitioned table referencing
1110+
-- a non-partitioned table fails.
1111+
ALTERTABLE ONLY fk_partitioned_fk ADDFOREIGN KEY (a, b)
1112+
REFERENCES fk_notpartitioned_pk;
1113+
-- Adding a NOT VALID foreign key on a partitioned table referencing
1114+
-- a non-partitioned table fails.
1115+
ALTERTABLE fk_partitioned_fk ADDFOREIGN KEY (a, b)
1116+
REFERENCES fk_notpartitioned_pk NOT VALID;
1117+
11091118
-- these inserts, targetting both the partition directly as well as the
11101119
-- partitioned table, should all fail
11111120
INSERT INTO fk_partitioned_fk (a,b)VALUES (500,501);

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp