Re: Q: insert/update in same statement

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: "G(dot) Ralph Kuntz, MD" <grk(at)usa(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Q: insert/update in same statement
Date: 2003-09-13 20:22:28
Message-ID: 20030913202228.GA25132@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Fri, Sep 12, 2003 at 10:55:17 -0700,
"G. Ralph Kuntz, MD" <grk(at)usa(dot)net> wrote:
> Is it possible to make a single SQL statement that will insert a row
> if it does not already exist, otherwise it will just update the
> fields?

No.

> Actually, just a statement that will not give an error about duplicate
> keys would be enough for my application.

This you can do by using a select statement that checks if the primary
key is a duplicate on the insert statement. An example was posted on
one of the lists about a week ago.

Note that there are conncurrency issues with doing this. Either you want
to exclusively lock the table or use serializable isolation and be
prepared to retry after failures.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Gregory S. Williamson 2003-09-13 20:50:36 Re: production parameters
Previous Message chester c young 2003-09-13 19:47:24 sorting