pg.ddx.io  pgsql-php@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Papp Gyozo <pgerzson@freestart.hu>
To: Christopher Kings-Lynne <chriskl@familyhealth.com.au>
To: PostgresSQL PHP list <pgsql-php@postgresql.org>
Subject: Re: "SQL" REPLACE SYNTAX
Date: Wed, 23 Jan 2002 12:15:37 +0100
Message-ID: <000a01c1a42f$ecf0b260$01fdfea9@jaguar> (raw)
References: <GNELIHDDFBOCMGBFGEFOKECFCBAA.chriskl@familyhealth.com.au>

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



view thread (15+ messages)  latest in thread

Message-ID: <000a01c1a42f$ecf0b260$01fdfea9@jaguar>
Permalink:  ../000a01c1a42f$ecf0b260$01fdfea9@jaguar/
Also on:    postgresql.org/message-id/000a01c1a42f$ecf0b260$01fdfea9@jaguar

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-php@postgresql.org
  Cc: pgerzson@freestart.hu, chriskl@familyhealth.com.au
  Subject: Re: "SQL" REPLACE SYNTAX
  In-Reply-To: <000a01c1a42f$ecf0b260$01fdfea9@jaguar>
  References: <GNELIHDDFBOCMGBFGEFOKECFCBAA.chriskl@familyhealth.com.au> <000a01c1a42f$ecf0b260$01fdfea9@jaguar>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox