Search Postgresql Archives

Re: Update on Insert

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> -----Original Message-----
> From: pgsql-general-owner@xxxxxxxxxxxxxx [mailto:pgsql-general-
> owner@xxxxxxxxxxxxxx] On Behalf Of Sebastian Feher
> Sent: Monday, November 16, 2009 10:41 AM
> To: pgsql-general@xxxxxxxxxxxxxx
> Subject:  Update on Insert
> 
> Hi Everyone,
> 
> Given a table "Items" with a PK "item1" and "Qty" - a numeric column
> I'd like to define a way in Postgres to insert when item11 doesn't
> exist already in "Items" and update the Qty by adding the new quantity
> to the existent when the item11 exists. What is a good approach and
> where should I be looking for details. Thanks.

That is called MERGE.  Merge is not currently supported:
http://www.postgresql.org/docs/8.4/interactive/unsupported-features-sql-
standard.html

You could set the transaction level to Serializable, start a
transaction, check for existence, if the row exists perform an update,
else perform an insert. Then commit.



-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux