NAKANO Yoshihisa <nakano(dot)yosihisa(at)jp(dot)fujitsu(dot)com> writes:
> Please find the patch attached. This is for the bug which is posted to
> hackers before.
> We can see a problem by this bug in following way.
> CREATE TABLE pktable (a int primary key);
> CREATE TABLE fktable (b int references pktable);
> ALTER TABLE pktable ALTER COLUMN a TYPE bigint; -- succeed
> REINDEX TABLE pg_depend;
> ALTER TABLE pktable ALTER COLUMN a TYPE int; -- fail
> NOTICE: constraint fktable_b_fkey on table fktable depends on index
> ERROR: cannot drop constraint pktable_pkey on table pktable because
> other objects depend on it
> HINT: Use DROP ... CASCADE to drop the dependent objects too.
Ah, thanks for providing the simple test case. Much nicer than
I don't much like the patch though :-(. It seems like a brute force
solution, and it's lacking error checking.
After looking at the test case a bit, I have an alternate approach:
constraints on the column will have DEPENDENCY_AUTO type, while
constraints using the column will have DEPENDENCY_NORMAL type.
Therefore, if we drop the NORMAL ones before the AUTO ones, that
should be enough to fix it. This doesn't require much extra code,
or any extra catalog searches, since the pg_depend record is already
available in ATExecAlterColumnType where we need to decide whether
to stick the item on the front or back of the list.
regards, tom lane
In response to
pgsql-patches by date
|Next:||From: Joshua D. Drake||Date: 2006-01-27 17:44:40|
|Subject: Re: Adding a --quiet option to initdb|
|Previous:||From: Tom Lane||Date: 2006-01-27 16:20:17|
|Subject: Re: Adding a --quiet option to initdb |