mirror of
				https://github.com/postgres/postgres.git
				synced 2025-11-03 09:13:20 +03:00 
			
		
		
		
	Fix ALTER TABLE error message
This bogus error message was introduced in 2013 by commitf177cbfe67, because of misunderstanding the processCASbits() API; at the time, no test cases were added that would be affected by this change. Only inca87c415e2was 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
This commit is contained in:
		@@ -2649,7 +2649,7 @@ alter_table_cmd:
 | 
				
			|||||||
					n->def = (Node *) c;
 | 
										n->def = (Node *) c;
 | 
				
			||||||
					c->contype = CONSTR_FOREIGN; /* others not supported, yet */
 | 
										c->contype = CONSTR_FOREIGN; /* others not supported, yet */
 | 
				
			||||||
					c->conname = $3;
 | 
										c->conname = $3;
 | 
				
			||||||
					processCASbits($4, @4, "ALTER CONSTRAINT statement",
 | 
										processCASbits($4, @4, "FOREIGN KEY",
 | 
				
			||||||
									&c->deferrable,
 | 
														&c->deferrable,
 | 
				
			||||||
									&c->initdeferred,
 | 
														&c->initdeferred,
 | 
				
			||||||
									NULL, NULL, yyscanner);
 | 
														NULL, NULL, yyscanner);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1278,11 +1278,15 @@ DETAIL:  Key (fk)=(20) is not present in table "pktable".
 | 
				
			|||||||
COMMIT;
 | 
					COMMIT;
 | 
				
			||||||
-- try additional syntax
 | 
					-- try additional syntax
 | 
				
			||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
 | 
					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 NOT DEFERRABLE INITIALLY DEFERRED;
 | 
				
			||||||
ERROR:  constraint declared INITIALLY DEFERRED must be DEFERRABLE
 | 
					ERROR:  constraint declared INITIALLY DEFERRED must be DEFERRABLE
 | 
				
			||||||
LINE 1: ...e ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE INITIALLY ...
 | 
					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
 | 
					-- 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
 | 
					-- be made to the same row.  This was broken by subtransaction-related
 | 
				
			||||||
-- changes in 8.0.
 | 
					-- changes in 8.0.
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -970,8 +970,10 @@ COMMIT;
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
-- try additional syntax
 | 
					-- try additional syntax
 | 
				
			||||||
ALTER TABLE fktable ALTER CONSTRAINT fktable_fk_fkey NOT DEFERRABLE;
 | 
					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 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
 | 
					-- 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
 | 
					-- be made to the same row.  This was broken by subtransaction-related
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user