Doing a conditional insert/update
От | Markus Holzer |
---|---|
Тема | Doing a conditional insert/update |
Дата | |
Msg-id | 978075550704191127g781a4a26i400f4fc80d491df6@mail.gmail.com обсуждение исходный текст |
Ответы |
Re: Doing a conditional insert/update
Re: Doing a conditional insert/update |
Список | 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 по дате отправления: