Doing a conditional insert/update - Mailing list pgsql-sql

From Markus Holzer
Subject Doing a conditional insert/update
Date
Msg-id 978075550704191127g781a4a26i400f4fc80d491df6@mail.gmail.com
Whole thread Raw
Responses Re: Doing a conditional insert/update  (Andrew Sullivan <ajs@crankycanuck.ca>)
Re: Doing a conditional insert/update  ("Rodrigo De León" <rdeleonp@gmail.com>)
List pgsql-sql
Hello.<br /><br />I'm currently developing my first web app with Postgres and I have a question. <br /><br />How do I
performa conditional insert/update? <br /><br />To clarify: I need to insert data into a table when the primary key is
notalready in the table, or an update if it is. I have currently solved this by SELECTing for the primary key, then
lookingif there is a row, and if there is I do an UPDATE otherwise I do an INSERT. But since this is a web app this way
ofcourse leaves a big race condition. <br /><br />Is there a way to get around that? Like the ON DUPLICATE KEY UPDATE
statementin MySQL?<br /><br /><br />Thanks for your time,<br /><br />Holli<span style="font-family: monospace;"><br
/></span><br/> 

pgsql-sql by date:

Previous
From: "Stuart McGraw"
Date:
Subject: Re: slowness when subselect uses DISTINCT
Next
From: Andrew Sullivan
Date:
Subject: Re: Doing a conditional insert/update