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

Commite16c9cd

Browse files
alvherrejianhe-funFujii Masaoamulsul
committed
Fix error message for ALTER CONSTRAINT ... NOT VALID
Trying to alter a constraint so that it becomes NOT VALID results in anerror that assumes the constraint is a foreign key. This is potentiallywrong, so give a more generic error message.While at it, give CREATE CONSTRAINT TRIGGER a better error message aswell.Co-authored-by: jian he <jian.universality@gmail.com>Co-authored-by: Fujii Masao <masao.fujii@oss.nttdata.com>Co-authored-by: Álvaro Herrera <alvherre@kurilemu.de>Co-authored-by: Amul Sul <sulamul@gmail.com>Discussion:https://postgr.es/m/CACJufxHSp2puxP=q8ZtUGL1F+heapnzqFBZy5ZNGUjUgwjBqTQ@mail.gmail.com
1 parent4cb889d commite16c9cd

File tree

4 files changed

+15
-1
lines changed

4 files changed

+15
-1
lines changed

‎src/backend/parser/gram.y‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2668,6 +2668,12 @@ alter_table_cmd:
26682668
c->alterDeferrability =true;
26692669
if ($4 & CAS_NO_INHERIT)
26702670
c->alterInheritability =true;
2671+
/* handle unsupported case with specific error message*/
2672+
if ($4 & CAS_NOT_VALID)
2673+
ereport(ERROR,
2674+
errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
2675+
errmsg("constraints cannot be altered to be NOT VALID"),
2676+
parser_errposition(@4));
26712677
processCASbits($4, @4,"FOREIGN KEY",
26722678
&c->deferrable,
26732679
&c->initdeferred,

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,11 @@ ALTER TABLE unique_tbl ALTER CONSTRAINT unique_tbl_i_key ENFORCED;
748748
ERROR: cannot alter enforceability of constraint "unique_tbl_i_key" of relation "unique_tbl"
749749
ALTER TABLE unique_tbl ALTER CONSTRAINT unique_tbl_i_key NOT ENFORCED;
750750
ERROR: cannot alter enforceability of constraint "unique_tbl_i_key" of relation "unique_tbl"
751+
-- can't make an existing constraint NOT VALID
752+
ALTER TABLE unique_tbl ALTER CONSTRAINT unique_tbl_i_key NOT VALID;
753+
ERROR: constraints cannot be altered to be NOT VALID
754+
LINE 1: ...ABLE unique_tbl ALTER CONSTRAINT unique_tbl_i_key NOT VALID;
755+
^
751756
DROP TABLE unique_tbl;
752757
--
753758
-- EXCLUDE constraints

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1359,7 +1359,7 @@ LINE 1: ...e ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY ...
13591359
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NO INHERIT;
13601360
ERROR: constraint "fktable_fk_fkey" of relation "fktable" is not a not-null constraint
13611361
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
1362-
ERROR:FOREIGN KEYconstraints cannot bemarked NOT VALID
1362+
ERROR: constraints cannot bealtered to be NOT VALID
13631363
LINE 1: ...ER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
13641364
^
13651365
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey ENFORCED NOT ENFORCED;

‎src/test/regress/sql/constraints.sql‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -537,6 +537,9 @@ CREATE TABLE UNIQUE_NOTEN_TBL(i int UNIQUE NOT ENFORCED);
537537
ALTERTABLE unique_tbl ALTERCONSTRAINT unique_tbl_i_key ENFORCED;
538538
ALTERTABLE unique_tbl ALTERCONSTRAINT unique_tbl_i_key NOT ENFORCED;
539539

540+
-- can't make an existing constraint NOT VALID
541+
ALTERTABLE unique_tbl ALTERCONSTRAINT unique_tbl_i_key NOT VALID;
542+
540543
DROPTABLE unique_tbl;
541544

542545
--

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp