X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id E9FE8D1D26A for ; Wed, 21 Apr 2004 04:33:33 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 32078-04 for ; Wed, 21 Apr 2004 04:33:34 -0300 (ADT) Received: from cyber12.e-insites.com (ns10.nic-reg-dns.com [66.206.10.2]) by svr1.postgresql.org (Postfix) with ESMTP id D08EBD1D263 for ; Wed, 21 Apr 2004 04:33:31 -0300 (ADT) Received: from server2k ([61.11.69.26]) by cyber12.e-insites.com with MailEnable ESMTP; Wed, 21 Apr 2004 00:33:31 -0700 Received: from 192.168.50.51 by server2k ([192.168.50.102] running VPOP3) with SMTP; Wed, 21 Apr 2004 13:11:56 +0530 X-MSReally-From: denis@coralindia.com Message-ID: <003d01c42772$4fc3bf00$3332a8c0@DENIS> From: denis@coralindia.com To: "Bruno Wolff III" , "H.J. Sanders" Cc: References: <20040421020010.GA19910@wolff.to> Subject: Re: transaction Date: Wed, 21 Apr 2004 12:58:56 +0530 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 5.00.2615.200 X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2615.200 X-Server: VPOP3 V1.5.0 - Registered X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.4 tagged_above=0.0 required=5.0 tests=NO_REAL_NAME, RCVD_IN_SORBS X-Spam-Level: X-Archive-Number: 200404/280 X-Sequence-Number: 17655 Hi, You can achieve this by: 1. Create a new table 2. Insert the data in this. 3. Write a trigger on this table 4. In trigger issue UPDATE and check whether it updated any records. If NO, fire INSERT. ( here, i am updating first and inserting.. just reverse ) The code looks like: update tempxitag set qty = qty + nqty where ccod = cccod GET DIAGNOSTICS nFound = ROW_COUNT; If nFound = 0 then insert into tempxitag( ccod, qty) values (cccod, nqty ); End if; HTH Denis ----- Original Message ----- From: Bruno Wolff III To: H.J. Sanders Cc: Sent: Wednesday, April 21, 2004 7:30 AM Subject: Re: [SQL] transaction > On Tue, Apr 20, 2004 at 21:14:48 +0200, > "H.J. Sanders" wrote: > > > > Hello list. > > > > We are migrating from Informix to PSQL. > > > > In Informix we used to do: > > > > - BEGIN WORK > > > > - INSERT ROW > > > > - IF FAILED THEN UPDATE ROW > > > > - COMMIT WORK > > > > > > In PSQL this does not seem to work because after the first error (the > > insert) > > everything is omitted. > > > > Has someone found a solution for this (we have 1000's of this type). > > This question has come up a few times over the last year and there isn't > a great answer. Locking the table is a simple solution, but can lead to > problems because of contention. > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings