Re: Add column if not exists (CINE)

From: Robert Haas <robertmhaas(at)gmail(dot)com>
To: Bernd Helmle <mailings(at)oopsware(dot)de>
Cc: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>, Heikki Linnakangas <heikki(dot)linnakangas(at)enterprisedb(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-07-21 21:16:13
Message-ID: AANLkTim4ti3OxVCNNTFSs+U_swPqTuppzjsgVDAH-k1G@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

On Wed, Jul 21, 2010 at 2:53 PM, Bernd Helmle <mailings(at)oopsware(dot)de> wrote:
>
>
> --On 1. Mai 2010 23:09:23 -0400 Robert Haas <robertmhaas(at)gmail(dot)com> wrote:
>
>> On Wed, Apr 28, 2010 at 9:15 PM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>>>>
>>>> CREATE OR REPLACE is indeed much more complicated.  In fact, for
>>>> tables, I maintain that you'll need to link with -ldwim to make it
>>>> work properly.
>>>
>>> This may in fact be an appropriate way to handle the case for tables,
>>> given the complexity of their definitions.
>>
>> Patch attached.
>
> I had an initial look at Robert's patch. Patch applies cleanly,
> documentation and regression tests included, everything works as expected.
> When looking at the functionality there's one thing that strikes me a
> little:
>
> bernd(at)localhost:bernd #*= CREATE TABLE IF NOT EXISTS foo(id int);
> ERROR:  duplicate key value violates unique constraint
> "pg_type_typname_nsp_index"
> DETAIL:  Key (typname, typnamespace)=(foo, 2200) already exists.
>
> This is what you get from concurrent CINE commands. The typname thingie
> might be confusing by unexperienced users, but i think its hard to do
> anything about it ?

I get the same error message from concurrent CREATE TABLE commands
even without CINE...

S1:
rhaas=# begin;
BEGIN
rhaas=# create table foo (id int);
CREATE TABLE

S2:
rhaas=# begin;
BEGIN
rhaas=# create table foo (id int);
<blocks>

S1:
rhaas=# commit;
COMMIT

S2:
ERROR: duplicate key value violates unique constraint
"pg_type_typname_nsp_index"
DETAIL: Key (typname, typnamespace)=(foo, 2200) already exists.

I agree it would be nice to fix this. I'm not sure how hard it is. I
don't think it's the job of this patch. :-)

--
Robert Haas
EnterpriseDB: http://www.enterprisedb.com
The Enterprise Postgres Company

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Andreas Joseph Krogh 2010-07-21 21:23:43 accentuated letters in text-search
Previous Message Dimitri Fontaine 2010-07-21 21:06:39 Re: managing git disk space usage