Skip site navigation (1) Skip section navigation (2)


From: "Florian G(dot) Pflug" <fgp(at)phlo(dot)org>
To: Andrew Dunstan <andrew(at)dunslane(dot)net>
Cc: Jonathan Scher <js(at)oxado(dot)com>, pgsql-hackers(at)postgresql(dot)org
Subject: Re: UPSERT
Date: 2007-03-02 14:49:00
Message-ID: (view raw or whole thread)
Lists: pgsql-hackers
Andrew Dunstan wrote:
> Jonathan Scher wrote:
>> Hello,
>> I'd like to work on TODO item:
>> > Add REPLACE or UPSERT command that does UPDATE, or on failure, INSERT
>> could you please tell me if I'm going in the right way?
>> There are some different syntaxes possible, but MySQL has an 
>> interesting one here:
>> INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1;
>> This allow to make an insert, and if the key is already there to 
>> modify the value depending on the current one.

May this could be generalized to a generic "<stmt> on <error> do <stmt>"?
You could then write
"update table set c=c+1 on not_found do insert into table (a,b,c) values (1,2,3)"

Just an idea I just had...

greetings, Florian Pflug

In response to

  • Re: UPSERT at 2007-03-02 14:35:20 from Andrew Dunstan


  • Re: UPSERT at 2007-03-02 15:06:52 from Gregory Stark

pgsql-hackers by date

Next:From: Gregory StarkDate: 2007-03-02 15:06:52
Subject: Re: UPSERT
Previous:From: Andrew DunstanDate: 2007-03-02 14:35:20
Subject: Re: UPSERT

Privacy Policy | About PostgreSQL
Copyright © 1996-2015 The PostgreSQL Global Development Group