Re: "SQL" REPLACE SYNTAX

Поиск
Список
Период
Сортировка
От Papp Gyozo
Тема Re: "SQL" REPLACE SYNTAX
Дата
Msg-id 000a01c1a42f$ecf0b260$01fdfea9@jaguar
обсуждение исходный текст
Ответ на "SQL" REPLACE SYNTAX  ("Christopher Kings-Lynne" <chriskl@familyhealth.com.au>)
Список 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 по дате отправления:

Предыдущее
От: Jeff Self
Дата:
Сообщение: Re: Not able to connect to server from PHP
Следующее
От: postgresql@finner.de
Дата:
Сообщение: Re: Long running queries and timeouts