pg.ddx.io pgsql-sql@postgresql.org mailing list archivehelp / color / mirror / Atom feed
Q: insert/update in same statement 2+ messages / 2 participants [nested] [flat]
* Q: insert/update in same statement @ 2003-09-12 17:55 G. Ralph Kuntz, MD <grk@usa.net> 2003-09-13 20:22 ` Re: Q: insert/update in same statement Bruno Wolff III <bruno@wolff.to> 0 siblings, 1 reply; 2+ messages in thread From: grk@usa.net @ 2003-09-12 17:55 UTC (permalink / raw) To: pgsql-sql 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? Actually, just a statement that will not give an error about duplicate keys would be enough for my application. Something like INSERT INTO SOME_TABLE (FIELD1, ...) VALUES (VALUE1, ...) WHERE KEY_FIELD DOES NOT EXIST; I am working in PostgreSQL 7.3.x. Thanks, Ralph ^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Q: insert/update in same statement 2003-09-12 17:55 Q: insert/update in same statement G. Ralph Kuntz, MD <grk@usa.net> @ 2003-09-13 20:22 ` Bruno Wolff III <bruno@wolff.to> 0 siblings, 0 replies; 2+ messages in thread From: Bruno Wolff III @ 2003-09-13 20:22 UTC (permalink / raw) To: G. Ralph Kuntz, MD <grk@usa.net>; +Cc: pgsql-sql On Fri, Sep 12, 2003 at 10:55:17 -0700, "G. Ralph Kuntz, MD" <grk@usa.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. ^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-09-13 20:22 UTC | newest] Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed) -- links below jump to the message on this page -- 2003-09-12 17:55 Q: insert/update in same statement G. Ralph Kuntz, MD <grk@usa.net> 2003-09-13 20:22 ` Bruno Wolff III <bruno@wolff.to>
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