Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 17DC419DE835 for ; Wed, 7 Mar 2012 16:31:49 -0400 (AST) Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1S5NWU-0008KF-2r for pgsql-bugs@postgresql.org; Wed, 07 Mar 2012 20:31:47 +0000 Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.2/8.14.2) with ESMTP id q27KVXnX018427; Wed, 7 Mar 2012 15:31:33 -0500 (EST) To: Merlin Moncure cc: Mike Blackwell , pgsql-bugs , PostgreSQL General Subject: Re: [GENERAL] Altering a table with a rowtype column In-reply-to: References: Comments: In-reply-to Merlin Moncure message dated "Wed, 07 Mar 2012 11:51:56 -0600" Date: Wed, 07 Mar 2012 15:31:32 -0500 Message-ID: <18426.1331152292@sss.pgh.pa.us> From: Tom Lane X-Pg-Spam-Score: -1.9 (-) X-Archive-Number: 201203/59 X-Sequence-Number: 32620 Merlin Moncure writes: > On Wed, Mar 7, 2012 at 11:45 AM, Mike Blackwell 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