Re: "SQL" REPLACE SYNTAX

From: "Papp Gyozo" <pgerzson(at)freestart(dot)hu>
To: "Christopher Kings-Lynne" <chriskl(at)familyhealth(dot)com(dot)au>, "PostgresSQL PHP list" <pgsql-php(at)postgresql(dot)org>
Subject: Re: "SQL" REPLACE SYNTAX
Date: 2002-01-23 11:15:37
Message-ID: 000a01c1a42f$ecf0b260$01fdfea9@jaguar
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php

Hi,
|
| BTW, from my estimates you'd need at least 4 - 6 sql queries to simulate the
| REPLACE syntax for Postgres, so why on earth would you use it?
|

I think Chris would be right. In my approach the true emulation of REPLACE
syntax is the following:

1. BEGIN;

2. SELECT ... FOR UPDATE;

3a. UPDATE ...;
3b. INSERT ...;

4. COMMIT;

I think each step is required to do a foolproof code.
Transaction (BEGIN and COMMIT) guarantees the atomicity for so called "REPLACE",
and the "FOR UPDATE" clause locks the corresponding row, if it exists.
(AFAIR, it works only in transaction, obvoiusly.)

So, it takes 4 SQL statements.

Papp Gyozo
- pgerzson(at)freestart(dot)hu

In response to

Browse pgsql-php by date

  From Date Subject
Next Message Vince Vielhaber 2002-01-23 11:24:48 Re: "SQL" REPLACE SYNTAX
Previous Message Andrew McMillan 2002-01-23 10:52:57 Re: "SQL" REPLACE SYNTAX