From: Bruno Wolff III <bruno@wolff.to>
To: Jeff Kowalczyk <jtk@yahoo.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: 'UPDATE OR INSERT' command
Date: Thu, 15 Jul 2004 12:53:18 -0500
Message-ID: <20040715175318.GA18875@wolff.to> (raw)
In-Reply-To: <pan.2004.07.15.18.20.54.67962@yahoo.com>
References: <pan.2004.07.15.18.20.54.67962@yahoo.com>
On Thu, Jul 15, 2004 at 13:20:57 -0500,
Jeff Kowalczyk <jtk@yahoo.com> wrote:
> Is there a postgresql SQL idiom to perform an UPDATE, which becomes an
> INSERT if the primary key does not exist?
>
> I'm not sure I *should* use it in my application, I just want to know if
> it can be done. Thanks.
There isn't a single statement that does this.
This has been discussed a number of times. The archives will have some
different examples.
You end up needing to either lock the table or check for failure since
postgres doesn't have predicate locking. Which technique is best will
depend on the details of your situation.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: bruno@wolff.to, jtk@yahoo.com
Subject: Re: 'UPDATE OR INSERT' command
In-Reply-To: <20040715175318.GA18875@wolff.to>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox