Re: Add column if not exists (CINE)

From: Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Robert Haas <robertmhaas(at)gmail(dot)com>, Andrew Dunstan <andrew(at)dunslane(dot)net>, Takahiro Itagaki <itagaki(dot)takahiro(at)oss(dot)ntt(dot)co(dot)jp>, Kjell Rune Skaaraas <kjella79(at)yahoo(dot)no>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: Add column if not exists (CINE)
Date: 2010-04-28 15:30:43
Message-ID: 4BD854A3.2010707@enterprisedb.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Tom Lane wrote:
> Robert Haas <robertmhaas(at)gmail(dot)com> writes:
>> I don't believe you are fairly stating the consensus from previous
>> discussion and I believe that you are actually in the minority on this
>> one. I agree that we probably don't need to support this for object
>> types for which CREATE OR REPLACE is available or can be made
>> available, but that isn't feasible for all object types - tables and
>> columns being the obvious examples.
>
> What's obvious about it? In particular, I should think that ADD OR
> REPLACE COLUMN would usefully be defined as "ADD if no such column,
> else ALTER COLUMN as necessary to match this spec". Dropping the
> ALTER part of that has no benefit except to lazy implementors; it
> certainly is not more useful to users if they can't be sure of the
> column properties after issuing the command.

Right. A trivial implementation of CREATE OR REPLACE is to create the
object if it doesn't exist, do nothing if it exists already and is
identical to the new definition, and throw an error if it's not
identical. That covers the same use case as CREATE IF NOT EXISTS, but
you know what the state is after a successful execution, is easy to
implement, and is in line with the existing CREATE OR REPLACE commands.
And can be extended in the future to alter the existing object instead
of throwing an error.

--
Heikki Linnakangas
EnterpriseDB http://www.enterprisedb.com

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2010-04-28 15:32:25 Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct
Previous Message Heikki Linnakangas 2010-04-28 15:25:19 Re: pg_start_backup and pg_stop_backup Re: Re: [COMMITTERS] pgsql: Make CheckRequiredParameterValues() depend upon correct