Re: Problems renaming referencing column - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Problems renaming referencing column
Date
Msg-id 15516.1090085451@sss.pgh.pa.us
Whole thread Raw
In response to Problems renaming referencing column  ("Alexander M. Pravking" <fduch@antar.bryansk.ru>)
List pgsql-bugs
"Alexander M. Pravking" <fduch@antar.bryansk.ru> writes:
> In 7.4.3, if I rename a column which references another table,
> constraint trigger fails on update or delete from main table.

The following patch (against 7.4.*) appears to fix this problem.

            regards, tom lane

Index: tablecmds.c
===================================================================
RCS file: /cvsroot/pgsql-server/src/backend/commands/tablecmds.c,v
retrieving revision 1.91
diff -c -r1.91 tablecmds.c
*** tablecmds.c    13 Oct 2003 22:47:15 -0000    1.91
--- tablecmds.c    17 Jul 2004 17:16:36 -0000
***************
*** 1534,1539 ****
--- 1534,1553 ----

          CatalogUpdateIndexes(tgrel, tuple);

+         /*
+          * Invalidate trigger's relation's relcache entry so that other
+          * backends (and this one too!) are sent SI message to make them
+          * rebuild relcache entries.  (Ideally this should happen
+          * automatically...)
+          *
+          * We can skip this for triggers on relid itself, since that
+          * relcache flush will happen anyway due to the table or column
+          * rename.  We just need to catch the far ends of RI relationships.
+          */
+         pg_trigger = (Form_pg_trigger) GETSTRUCT(tuple);
+         if (pg_trigger->tgrelid != relid)
+             CacheInvalidateRelcache(pg_trigger->tgrelid);
+
          /* free up our scratch memory */
          pfree(newtgargs);
          heap_freetuple(tuple);

pgsql-bugs by date:

Previous
From: Tom Lane
Date:
Subject: Re: Problems renaming referencing column
Next
From: "PostgreSQL Bugs List"
Date:
Subject: BUG #1195: foreignkey-bug