Skip site navigation (1) Skip section navigation (2)

Insert with replace?

From: Steve Wampler <swampler(at)noao(dot)edu>
To: postgres-sql <pgsql-sql(at)postgresql(dot)org>
Subject: Insert with replace?
Date: 2000-05-30 17:36:38
Message-ID: 3933FC26.E90C0F10@noao.edu (view raw or flat)
Thread:
Lists: pgsql-sql
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(at)noao(dot)edu

pgsql-sql by date

Next:From: Tom LaneDate: 2000-05-30 17:41:55
Subject: Re: Re: [SQL] remove line type?
Previous:From: Tom LaneDate: 2000-05-30 17:19:35
Subject: Re: Pg/PLSQL Errors!!

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group