pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Thomas Good <tomg@admin.nrnet.org>
To: Alessio Bragadini <alessio@albourne.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: MySql 'REPLACE'
Date: Wed, 25 Apr 2001 09:06:21 -0400 (EDT)
Message-ID: <Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org> (raw)
In-Reply-To: <3AE6C553.74036D93@albourne.com>

On Wed, 25 Apr 2001, Alessio Bragadini wrote:

> I am working in porting the Slash software from MySql to PostgreSQL. I
> stepped in MySql's REPLACE command (a SQL command) that to my knowledge
> is not supported by PostgreSQL and it's not standard SQL. According to
> MySql's manual:
> 
> "REPLACE works exactly like INSERT, except that if an old record in the
> table has the same value as a new record on a unique index, the old
> record is
> deleted before the new record is inserted. See section 7.21 INSERT
> syntax."
> 
> REPLACE INTO table (column, column...) VALUES (value, value...)
> 
> Has anyone had any experience about how to simulate it under PostgreSQL?
> I am using Perl and I can move most of the thing into application
> anyway.

Hi, I did this in moving a query from a deprecated* (INSERT INTO ... SELECT) 
form to two separate queries...using perl.  My statement handle for the
select cursor grabbed all of the values and then passed them to an insert.
In your case I'd guess you could grab the pkey in a $sth->fetchrow_array()
(or hashref) and do a delete & insert in a $dbh->do() series?

Good luck,
Tom

* deprecated according to SQL In A Nutshell and other SQL3 ref guides.
--------------------------------------------------------------------
               SVCMC - Center for Behavioral Health                  
--------------------------------------------------------------------
Thomas Good                          tomg@ { admin | q8 } .nrnet.org
Database Administrator                          Phone:  718-354-5528 
Staten Island Region                            Mobile: 917-282-7359  
--------------------------------------------------------------------
Powered by:  PostgreSQL     s l a c k w a r e          FreeBSD:
               RDBMS       |---------- linux      The Power To Serve
--------------------------------------------------------------------

     /* We prefer linguistic vigor over mathematical rigor. */ 




view thread (6+ messages)  latest in thread

Message-ID: <Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org>
Permalink:  ../Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org/
Also on:    postgresql.org/message-id/Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org

 · 

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 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: tomg@admin.nrnet.org, alessio@albourne.com
  Subject: Re: MySql 'REPLACE'
  In-Reply-To: <Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org>
  References: <3AE6C553.74036D93@albourne.com> <Pine.LNX.4.05.10104250857021.26314-100000@admin.nrnet.org>

* 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