pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@[66.92.219.49]>
To: Terrence Brannon <metaperl@mac.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: how does one replace a row in Postgresql? (ala MySQL REPLACE)
Date: Wed, 12 Dec 2001 06:45:56 -0600
Message-ID: <20011212064556.A32473@wolff.to> (raw)
In-Reply-To: <B9A8DB2D-EE83-11D5-9845-003065C2A10C@mac.com>
References: <20011210131528.C70079-100000@megazone23.bigpanda.com>
	<B9A8DB2D-EE83-11D5-9845-003065C2A10C@mac.com>

On Tue, Dec 11, 2001 at 02:09:19PM -0800,
  Terrence Brannon <metaperl@mac.com> 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.



view thread (3+ messages)

Message-ID: <20011212064556.A32473@wolff.to>
Permalink:  ../20011212064556.A32473@wolff.to/
Also on:    postgresql.org/message-id/20011212064556.A32473@wolff.to

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@[66.92.219.49], metaperl@mac.com
  Subject: Re: how does one replace a row in Postgresql? (ala MySQL REPLACE)
  In-Reply-To: <20011212064556.A32473@wolff.to>

* 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