On Thu, 8 May 2003, [iso-8859-1] Erik Ronstr�m wrote:
> Still stuck with the same error. Finally managed to upgrade from 7.2.1
> to 7.2.4, and realized that the problem is still there. Shit! I've not
> yet been able to reproduce the problem on another location, but at
> least I've isolated it a bit:
>
> I have a function which creates a "cache" table with a subset of rows
> from another table (CREATE TABLE new AS SELECT ... FROM old WHERE ...).
> Then it adds a foreign key (ALTER TABLE new ADD CONSTRAINT ref FOREIGN
> KEY ... REFERENCES old). Everything is fine so far. Now, if I drop the
> new table and run the function again, postgres crashes.
I can reproduce on 7.2 but not 7.3 or 7.4. It looks like something is
getting clobbered. When I recompiled with debug and asserting, I get a
crash the first time the function is called. You may need to go through
with a debugger.
> One question is: is it always safe to create a foreign key constraint,
> even when the table contains data?
It'll error if the constraint is violated or invalid, but otherwise it
should be.