Received: from mail2.panix.com (mail2.panix.com [166.84.0.213]) by postgresql.org (8.11.3/8.11.1) with ESMTP id f3PD2v398377 for ; Wed, 25 Apr 2001 09:02:57 -0400 (EDT) (envelope-from tomg@admin.nrnet.org) Received: from mailhost.nrnet.org (mailhost.nrnet.org [166.84.192.39]) by mail2.panix.com (Postfix) with ESMTP id 757AD8EFC; Wed, 25 Apr 2001 09:02:50 -0400 (EDT) Received: from admin.nrnet.org (uucp@localhost) by mailhost.nrnet.org (8.9.3/8.9.3) with UUCP id JAA17931; Wed, 25 Apr 2001 09:03:00 -0400 Received: from localhost (tomg@localhost) by admin.nrnet.org (8.9.1/8.9.1) with ESMTP id JAA26712; Wed, 25 Apr 2001 09:06:21 -0400 Date: Wed, 25 Apr 2001 09:06:21 -0400 (EDT) From: Thomas Good To: Alessio Bragadini Cc: pgsql-sql@postgresql.org Subject: Re: MySql 'REPLACE' In-Reply-To: <3AE6C553.74036D93@albourne.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII X-Archive-Number: 200104/375 X-Sequence-Number: 2733 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. */