pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Robert Haas <robertmhaas@gmail.com>
Cc: 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: Tue, 20 Mar 2012 14:48:46 -0400
Message-ID: <29346.1332269326@sss.pgh.pa.us> (raw)
In-Reply-To: <CA+TgmobFiwU8ny1Sy8tHR_XyHsy3pgCMJJE36e68fBP6bTKQJg@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>
	<18426.1331152292@sss.pgh.pa.us>
	<CAHyXU0xL970eAwXNwSRCMoMQr=WebLcMV+H4zBUAstEjohx8yg@mail.gmail.com>
	<CA+TgmobFiwU8ny1Sy8tHR_XyHsy3pgCMJJE36e68fBP6bTKQJg@mail.gmail.com>

Robert Haas <robertmhaas@gmail.com> writes:
> On Wed, Mar 7, 2012 at 3:49 PM, Merlin Moncure <mmoncure@gmail.com> wrote:
>> On Wed, Mar 7, 2012 at 2:31 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>>> 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.

>> I'm not buying that..it implies no such thing.  In particular, for
>> table-as-rowtype columns, there's no way that I can see to have
>> default values be generated.  So why does it follow that the dependent
>> table has to be rewritten?  Column constraints are not enforced on the
>> rowtype, so it follows that default shouldn't be either considering
>> there's no way to get the default to fire.  Composite type (or table
>> based composite) defaults are applied to the composite as a whole, not
>> to specific fields.

> I think Tom's correct about what the right behavior would be if
> composite types supported defaults, but they don't, never have, and
> maybe never will.  I had a previous argument about this with Tom, and
> lost, though I am not sure that anyone other than Tom thinks that the
> current behavior is for the best.

Um, did I say I thought it was for the best?  I thought I said we don't
have support for doing better.

If we are willing to legislate that column defaults are not and never
will be applied to composite types, then I think Merlin might be right
that we could just let an ALTER ADD with DEFAULT ignore the existence of
composite columns.  I'd always figured that we'd want to try to fix that
omission eventually, though.

> But see commits
> a06e41deebdf74b8b5109329dc75b2e9d9057962 and
> a40b1e0bf32b1da46c1baa9bc7da87f207cd37d8.

Note that the actual problem with the original commit was that it
depended on a misreading of the SQL standard.  Per spec, ALTER ADD with
DEFAULT is *not* the same thing as ALTER ADD followed by ALTER SET
DEFAULT; the contents of the table end up different.

			regards, tom lane



view thread (14+ messages)  latest in thread

Message-ID: <29346.1332269326@sss.pgh.pa.us>
Permalink:  ../29346.1332269326@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/29346.1332269326@sss.pgh.pa.us

 · 

reply

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, robertmhaas@gmail.com, mmoncure@gmail.com, mike.blackwell@rrd.com, pgsql-general@postgresql.org
  Subject: Re: [GENERAL] Altering a table with a rowtype column
  In-Reply-To: <29346.1332269326@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> <CAHyXU0xL970eAwXNwSRCMoMQr=WebLcMV+H4zBUAstEjohx8yg@mail.gmail.com> <CA+TgmobFiwU8ny1Sy8tHR_XyHsy3pgCMJJE36e68fBP6bTKQJg@mail.gmail.com> <29346.1332269326@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