From: Steve Wampler <swampler@noao.edu>
To: postgres-sql <pgsql-sql@postgresql.org>
Subject: Insert with replace?
Date: Tue, 30 May 2000 10:36:38 -0700
Message-ID: <3933FC26.E90C0F10@noao.edu> (raw)
What is the normal way to preform a "insert with replace" on
a row in a relational database (specifically postgresql)?
I've got a database that (logically) represents a set of
items, where each item has a primary key represented by two
columns (id and name). If that key isn't in the database,
I want to insert the item. If that key is in the database, I want
to update the item. I have no need to retain the previous
values.
The interface is through jdbc.
I assume I could try the update first and then, if the update
generates an exception, perform an insert, but is there a way
to do the same with a single command? (The data is such that
the update will fail in the majority of cases.)
Thanks!
--
Steve Wampler- SOLIS Project, National Solar Observatory
swampler@noao.edu
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: swampler@noao.edu
Subject: Re: Insert with replace?
In-Reply-To: <3933FC26.E90C0F10@noao.edu>
References: <3933FC26.E90C0F10@noao.edu>
* 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