Re: [GENERAL] Altering a table with a rowtype column

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: Mike Blackwell <mike(dot)blackwell(at)rrd(dot)com>, pgsql-bugs <pgsql-bugs(at)postgresql(dot)org>, PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: [GENERAL] Altering a table with a rowtype column
Date: 2012-03-07 20:31:32
Message-ID: 18426.1331152292@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-general

Merlin Moncure <mmoncure(at)gmail(dot)com> writes:
> On Wed, Mar 7, 2012 at 11:45 AM, Mike Blackwell <mike(dot)blackwell(at)rrd(dot)com> wrote:
>> alter table a add column even_more_stuff boolean not null default false;

> aha! that's not what you posted last time. you appended 'not null
> default false'; which inexplicably breaks the ALTER.

> try this:
> ALTER TABLE a ADD COLUMN even_more_stuff text not null;
> ALTER TABLE a ALTER even_more_stuff set default false;
> ALTER TABLE a DROP COLUMN even_more_stuff;
> ALTER TABLE a ADD COLUMN even_more_stuff boolean not null default false;

> (this really looks like a bug in postgres, cc-ing to bugs)

It is not a bug. The ALTER ADD ... DEFAULT ... form implies rewriting
every existing tuple of the rowtype to insert a non-null value in the
added column, and we don't have support for doing that to rowtype
columns, only to the target table and descendants. Without a default,
it's just a catalog adjustment and doesn't involve rewriting any data.
(This stems from the fact that columns beyond a tuple's natts value are
presumed null, so we can let ADD COLUMN without a default just change
the catalogs and a null column effectively springs into existence for
every existing tuple. ALTER ADD ... DEFAULT is specified to have a
different result, and it's not free.)

This probably could be done for rowtype columns as well, but nobody has
collected the necessary round tuits. I think there was some fear of
locking/deadlock issues, too.

regards, tom lane

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Alvaro Herrera 2012-03-07 20:49:22 Re: [GENERAL] Altering a table with a rowtype column
Previous Message Merlin Moncure 2012-03-07 20:11:55 Re: [GENERAL] Altering a table with a rowtype column

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2012-03-07 20:49:22 Re: [GENERAL] Altering a table with a rowtype column
Previous Message pawel_kukawski 2012-03-07 20:13:26 autovacuum and transaction id wraparound