Skip to content

Commit 0f354e0

Browse files
committed
Fix ALTER TABLE error message
This bogus error message was introduced in 2013 by commit f177cbf, because of misunderstanding the processCASbits() API; at the time, no test cases were added that would be affected by this change. Only in ca87c41 was one added (along with a couple of typos), with an XXX note that the error message was bogus. Fix the whole, add some test cases. Backpatch all the way back. Reviewed-by: Nathan Bossart <nathandbossart@gmail.com> Discussion: https://postgr.es/m/202503041822.aobpqke3igvb@alvherre.pgsql
1 parent aac07b5 commit 0f354e0

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/backend/parser/gram.y

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2318,7 +2318,7 @@ alter_table_cmd:
23182318
n->def = (Node *) c;
23192319
c->contype = CONSTR_FOREIGN; /* others not supported, yet */
23202320
c->conname = $3;
2321-
processCASbits($4, @4, "ALTER CONSTRAINT statement",
2321+
processCASbits($4, @4, "FOREIGN KEY",
23222322
&c->deferrable,
23232323
&c->initdeferred,
23242324
NULL, NULL, yyscanner);

src/test/regress/expected/foreign_key.out

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1240,11 +1240,15 @@ DETAIL: Key (fk)=(20) is not present in table "pktable".
12401240
COMMIT;
12411241
-- try additional syntax
12421242
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
1243-
-- illegal option
1243+
-- illegal options
12441244
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
12451245
ERROR: constraint declared INITIALLY DEFERRED must be DEFERRABLE
12461246
LINE 1: ...e ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY ...
12471247
^
1248+
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NO INHERIT;
1249+
ERROR: FOREIGN KEY constraints cannot be marked NO INHERIT
1250+
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
1251+
ERROR: FOREIGN KEY constraints cannot be marked NOT VALID
12481252
-- test order of firing of FK triggers when several RI-induced changes need to
12491253
-- be made to the same row. This was broken by subtransaction-related
12501254
-- changes in 8.0.

src/test/regress/sql/foreign_key.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -943,8 +943,10 @@ COMMIT;
943943

944944
-- try additional syntax
945945
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
946-
-- illegal option
946+
-- illegal options
947947
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
948+
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NO INHERIT;
949+
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
948950

949951
-- test order of firing of FK triggers when several RI-induced changes need to
950952
-- be made to the same row. This was broken by subtransaction-related

0 commit comments

Comments
 (0)