From: Tom Lane <tgl@sss.pgh.pa.us>
To: Merlin Moncure <mmoncure@gmail.com>
Cc: Mike Blackwell <mike.blackwell@rrd.com>
Cc: pgsql-bugs <pgsql-bugs@postgresql.org>
Cc: PostgreSQL General <pgsql-general@postgresql.org>
Subject: Re: [GENERAL] Altering a table with a rowtype column
Date: Wed, 07 Mar 2012 15:31:32 -0500
Message-ID: <18426.1331152292@sss.pgh.pa.us> (raw)
In-Reply-To: <CAHyXU0yBCz5t8BqfBK7M9dSWNw4+hvV9BWAizy9ZXhNYxTBAww@mail.gmail.com>
References: <CANPAkgsA3CrSzK_soK_FTO4S9jcwkA2T4EmQ-=tDzSq7rOhsLg@mail.gmail.com>
<CAHyXU0xHT4xNPydEgCvzn=+HqmeH4=8WNxGJnyFp_gitYwzTZw@mail.gmail.com>
<CANPAkgsyUtvNvzSoaS+--LP15hwAVSwh04QQtfNbFY1=9ip7Jg@mail.gmail.com>
<CAHyXU0yBCz5t8BqfBK7M9dSWNw4+hvV9BWAizy9ZXhNYxTBAww@mail.gmail.com>
Merlin Moncure <mmoncure@gmail.com> writes:
> On Wed, Mar 7, 2012 at 11:45 AM, Mike Blackwell <mike.blackwell@rrd.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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, mmoncure@gmail.com, mike.blackwell@rrd.com, pgsql-general@postgresql.org
Subject: Re: [GENERAL] Altering a table with a rowtype column
In-Reply-To: <18426.1331152292@sss.pgh.pa.us>
References: <CANPAkgsA3CrSzK_soK_FTO4S9jcwkA2T4EmQ-=tDzSq7rOhsLg@mail.gmail.com> <CAHyXU0xHT4xNPydEgCvzn=+HqmeH4=8WNxGJnyFp_gitYwzTZw@mail.gmail.com> <CANPAkgsyUtvNvzSoaS+--LP15hwAVSwh04QQtfNbFY1=9ip7Jg@mail.gmail.com> <CAHyXU0yBCz5t8BqfBK7M9dSWNw4+hvV9BWAizy9ZXhNYxTBAww@mail.gmail.com> <18426.1331152292@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox