Re: What is the postgres version of mysql's "ON DUPLICATE KEY"

From: Pierre-Frédéric Caillaud <lists(at)boutiquenumerique(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: What is the postgres version of mysql's "ON DUPLICATE KEY"
Date: 2004-09-11 10:48:20
Message-ID: opsd5sauwxcq72hf@musicbox
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> INSERT INTO related_products (product_id,related_product_id)
> SELECT 1, 2 WHERE NOT EXISTS (SELECT 1
> FROM
> related_products
> WHERE
> product_id = 1 AND related_product_id = 2)

Should not the SELECT be FOR UPDATE ?
because if no insert is done, the OP wanted to UPDATE the row, so it
should not be deleted by another transaction in-between...

Can the above query fail if another transaction inserts a row between the
SELECT and the INSERT or postgres guarantee that this won't happen ?

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Peter Eisentraut 2004-09-11 11:56:26 Re: What is the postgres version of mysql's "ON DUPLICATE KEY"
Previous Message Devrim GUNDUZ 2004-09-11 10:45:03 Re: Where can I get pgsqlodbc now gborg is down?