Re: "SQL" REPLACE SYNTAX

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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@xxxxxxxxxxxx


[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux