Search Postgresql Archives

Re: is there a select for update insert if not exist type command?

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

 



Depending on the version of Pg there are two possible solutions to
this problem.  The first (old solution) that really only works well
one row at a time is to do a stored procedure that does something
like:

update foo set bar = baz where id = in_id

if not found
   insert into foo (bar) values (baz)
end if;

The newer way, which can be done in SQL with Pg 9.1 is to use writable
common table expressions.  See
http://vibhorkumar.wordpress.com/2011/10/26/upsertmerge-using-writable-cte-in-postgresql-9-1/
for an example by Vibhor Kumar.

Best Wishes,
Chris Travers

-- 
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