Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Fix ALTER TABLE error message
authorÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 4 Mar 2025 19:07:30 +0000 (20:07 +0100)
committerÁlvaro Herrera <alvherre@alvh.no-ip.org>
Tue, 4 Mar 2025 19:07:30 +0000 (20:07 +0100)
This bogus error message was introduced in 2013 by commit f177cbfe676d,
because of misunderstanding the processCASbits() API; at the time, no
test cases were added that would be affected by this change.  Only in
ca87c415e2fc 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

src/backend/parser/gram.y
src/test/regress/expected/foreign_key.out
src/test/regress/sql/foreign_key.sql

index 5433a264cff7942761524bab1b850c9632f6743f..8379e48c97b1c7d6372df464dfb959bfa2f4f532 100644 (file)
@@ -2559,7 +2559,7 @@ alter_table_cmd:
                    n->def = (Node *) c;
                    c->contype = CONSTR_FOREIGN; /* others not supported, yet */
                    c->conname = $3;
-                   processCASbits($4, @4, "ALTER CONSTRAINT statement",
+                   processCASbits($4, @4, "FOREIGN KEY",
                                    &c->deferrable,
                                    &c->initdeferred,
                                    NULL, NULL, yyscanner);
index ff6b4e23fe899ae2f8cad7539eb6f243a63550dd..c8c2f420a2be992542711d9bab52a9ed69c3f3b6 100644 (file)
@@ -1278,11 +1278,15 @@ DETAIL:  Key (fk)=(20) is not present in table "pktable".
 COMMIT;
 -- try additional syntax
 ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
--- illegal option
+-- illegal options
 ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
 ERROR:  constraint declared INITIALLY DEFERRED must be DEFERRABLE
 LINE 1: ...e ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY ...
                                                              ^
+ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NO INHERIT;
+ERROR:  FOREIGN KEY constraints cannot be marked NO INHERIT
+ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
+ERROR:  FOREIGN KEY constraints cannot be marked NOT VALID
 -- test order of firing of FK triggers when several RI-induced changes need to
 -- be made to the same row.  This was broken by subtransaction-related
 -- changes in 8.0.
index 98e4d2bf481dbdd70ebdbff331eb6235fac1d93e..978387740b350473ab1c5580e10706d3bd147446 100644 (file)
@@ -970,8 +970,10 @@ COMMIT;
 
 -- try additional syntax
 ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
--- illegal option
+-- illegal options
 ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY DEFERRED;
+ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NO INHERIT;
+ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT VALID;
 
 -- test order of firing of FK triggers when several RI-induced changes need to
 -- be made to the same row.  This was broken by subtransaction-related