Re: "SQL" REPLACE SYNTAX - Mailing list pgsql-php

From Papp Gyozo
Subject Re: "SQL" REPLACE SYNTAX
Date
Msg-id 000a01c1a42f$ecf0b260$01fdfea9@jaguar
Whole thread Raw
In response to "SQL" REPLACE SYNTAX  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
List 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@freestart.hu

pgsql-php by date:

Previous
From: Jeff Self
Date:
Subject: Re: Not able to connect to server from PHP
Next
From: postgresql@finner.de
Date:
Subject: Re: Long running queries and timeouts