Re: 'UPDATE OR INSERT' command

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Jeff Kowalczyk <jtk(at)yahoo(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: 'UPDATE OR INSERT' command
Date: 2004-07-15 17:53:18
Message-ID: 20040715175318.GA18875@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Thu, Jul 15, 2004 at 13:20:57 -0500,
Jeff Kowalczyk <jtk(at)yahoo(dot)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.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Jeff Kowalczyk 2004-07-15 18:20:57 'UPDATE OR INSERT' command
Previous Message Stephen Frost 2004-07-15 17:49:32 Re: 'UPDATE OR INSERT' command