Re: 'UPDATE OR INSERT' command - Mailing list pgsql-sql

From Bruno Wolff III
Subject Re: 'UPDATE OR INSERT' command
Date
Msg-id 20040715175318.GA18875@wolff.to
Whole thread Raw
In response to 'UPDATE OR INSERT' command  (Jeff Kowalczyk <jtk@yahoo.com>)
List pgsql-sql
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.


pgsql-sql by date:

Previous
From: Jeff Kowalczyk
Date:
Subject: 'UPDATE OR INSERT' command
Next
From: Stephen Frost
Date:
Subject: Re: 'UPDATE OR INSERT' command