Received: from wolff.to (wolff.to [66.92.219.49] (may be forged)) by postgresql.org (8.11.3/8.11.4) with SMTP id fBCCkfm37790 for ; Wed, 12 Dec 2001 07:46:42 -0500 (EST) (envelope-from bruno@[66.92.219.49]) Received: (qmail 32479 invoked by uid 500); 12 Dec 2001 12:45:57 -0000 Date: Wed, 12 Dec 2001 06:45:56 -0600 From: Bruno Wolff III To: Terrence Brannon Cc: pgsql-sql@postgresql.org Subject: Re: how does one replace a row in Postgresql? (ala MySQL REPLACE) Message-ID: <20011212064556.A32473@wolff.to> Mail-Followup-To: Terrence Brannon , pgsql-sql@postgresql.org References: <20011210131528.C70079-100000@megazone23.bigpanda.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: ; from metaperl@mac.com on Tue, Dec 11, 2001 at 02:09:19PM -0800 X-Archive-Number: 200112/121 X-Sequence-Number: 5944 On Tue, Dec 11, 2001 at 02:09:19PM -0800, Terrence Brannon wrote: > A common task is to check to see if a row with a certain primary > key exists before inserting it. If the row exists, then you > simply update/overwrite its contents with the new row data. > Otherwise you insert it. > > MySQL has a REPLACE command which does this. > > I didn't see one in the Postgresql manual. How do you do this in > Postgresql? Another option that doesn't require testing of the response from one sql statement before executing another is to delete rows with the matching primary key. Then do an insert.