Skip site navigation (1) Skip section navigation (2)

Re: Patch for ALTER TABLE / TYPE

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: NAKANO Yoshihisa <nakano(dot)yosihisa(at)jp(dot)fujitsu(dot)com>
Cc: pgsql-patches(at)postgresql(dot)org, Neil Conway <neilc(at)samurai(dot)com>
Subject: Re: Patch for ALTER TABLE / TYPE
Date: 2006-01-27 16:43:24
Message-ID: 3111.1138380204@sss.pgh.pa.us (view raw or flat)
Thread:
Lists: pgsql-patches
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.
> 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

In response to

Responses

pgsql-patches by date

Next:From: Joshua D. DrakeDate: 2006-01-27 17:44:40
Subject: Re: Adding a --quiet option to initdb
Previous:From: Tom LaneDate: 2006-01-27 16:20:17
Subject: Re: Adding a --quiet option to initdb

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group