Re: Patch for ALTER TABLE / TYPE

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Patch for ALTER TABLE / TYPE
Дата
Msg-id 3111.1138380204@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Patch for ALTER TABLE / TYPE  (NAKANO Yoshihisa <nakano.yosihisa@jp.fujitsu.com>)
Ответы Re: Patch for ALTER TABLE / TYPE
Список pgsql-patches
NAKANO Yoshihisa <nakano.yosihisa@jp.fujitsu.com> writes:
> Please find the patch attached.  This is for the bug which is posted to
> hackers before.
> http://archives.postgresql.org/pgsql-hackers/2005-06/msg01442.php

> 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
> pktable_pkey
> 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
Neil's way...

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

В списке pgsql-patches по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: BTree vacuum before page splitting
Следующее
От: Andrew Dunstan
Дата:
Сообщение: Re: plperl / locale / win32