Re: MySql 'REPLACE'

From: Thomas Swan <tswan(at)ics(dot)olemiss(dot)edu>
To: Alessio Bragadini <alessio(at)albourne(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: MySql 'REPLACE'
Date: 2001-04-25 13:43:02
Message-ID: 5.1.0.14.0.20010425082557.00ae1830@tangent.ics.olemiss.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

At 4/25/2001 07:38 AM, you 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.

You should be able to do this with two separate queries inside a transaction.

The only part I'm not clear on is whether to use an 'and' or an 'or' on the
delete. Check and see if all values have to match or if partial matches,
i.e. only one of the columns, are acceptable. If it does partial matching,
then use the 'or', otherwise use the 'and'.

Give this a try...
begin;
delete from table where (column=value) and (column=value) and ...;
insert into table (column, column...) values (value, value...);
end;

From what you've given me, I think this would emulate that behavior.

Hope it helps...

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Alessio Bragadini 2001-04-25 15:25:40 Re: MySql 'REPLACE'
Previous Message Thomas Good 2001-04-25 13:06:21 Re: MySql 'REPLACE'