Received: from pompom.freestart.hu (pompom.freestart.hu [213.197.64.6]) by postgresql.org (8.11.3/8.11.4) with ESMTP id g0NH2xl11763 for ; Wed, 23 Jan 2002 12:03:03 -0500 (EST) (envelope-from pgerzson@freestart.hu) Received: from line-75-121.dial.freestart.hu ([213.197.75.121] helo=jaguar) by freestart.hu with smtp (Freestart relay 1 (FS-Lin)) id 16TQmh-0001DG-00; Wed, 23 Jan 2002 18:02:03 +0100 Message-ID: <000a01c1a42f$ecf0b260$01fdfea9@jaguar> From: "Papp Gyozo" To: "Christopher Kings-Lynne" , "PostgresSQL PHP list" References: Subject: Re: "SQL" REPLACE SYNTAX Date: Wed, 23 Jan 2002 12:15:37 +0100 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-2" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-Scanner: exiscan by Freestart Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from base64 to 8bit by postgresql.org id g0NHCUm15682 X-Archive-Number: 200201/66 X-Sequence-Number: 870 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