Received: from noao.edu (root@noao.edu [140.252.1.54]) by hub.org (8.9.3/8.9.3) with ESMTP id NAA23939 for ; Tue, 30 May 2000 13:36:42 -0400 (EDT) (envelope-from swampler@noao.edu) Received: from reynaud.tuc.noao.edu (reynaud.tuc.noao.edu [140.252.38.6]) by noao.edu (8.9.3/8.8.8/SAG-27Sep99) with ESMTP id KAA00551 for ; Tue, 30 May 2000 10:36:40 -0700 (MST) (envelope-from swampler@noao.edu) Received: from noao.edu by reynaud.tuc.noao.edu (8.9.1b+Sun/SMI-SVR4-SAG05) id KAA09759; Tue, 30 May 2000 10:36:38 -0700 (MST) Message-ID: <3933FC26.E90C0F10@noao.edu> Date: Tue, 30 May 2000 10:36:38 -0700 From: Steve Wampler Organization: National Solar Observatory X-Mailer: Mozilla 4.7 [en] (X11; I; SunOS 5.7 sun4u) X-Accept-Language: en MIME-Version: 1.0 To: postgres-sql Subject: Insert with replace? Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Archive-Number: 200005/206 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