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 EA056D1B197 for ; Tue, 11 May 2004 03:02:26 -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 03811-10 for ; Tue, 11 May 2004 03:02:06 -0300 (ADT) Received: from ar-sd.net (unknown [81.196.32.112]) by svr1.postgresql.org (Postfix) with ESMTP id 2D5D4D1B262 for ; Tue, 11 May 2004 03:02:05 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by ar-sd.net (Postfix) with ESMTP id E0D1020E2D; Tue, 11 May 2004 08:01:44 +0300 (EEST) Received: from forge (unknown [192.168.0.11]) by ar-sd.net (Postfix) with SMTP id C3D0020C51; Tue, 11 May 2004 08:01:44 +0300 (EEST) Message-ID: <007001c4371d$8560f640$0b00a8c0@forge> From: "Andrei Bintintan" To: "Stef" , References: <20040510150808.7ea12c06@svb.ucs.co.za> Subject: Re: Exceptions when 0 rows affected. Date: Tue, 11 May 2004 09:02:19 +0300 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 6.00.2720.3000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2739.300 X-Virus-Scanned: by AMaViS snapshot-20020531 X-Virus-Scanned: by amavisd-new at postgresql.org X-Spam-Status: No, hits=0.0 tagged_above=0.0 required=5.0 tests= X-Spam-Level: X-Archive-Number: 200405/93 X-Sequence-Number: 17807 Hi Stef, Your problem depends on what interface/programming language you're using. In a Begin End transaction you will have to verify if the returned data is good for you so then you decide if you run at the end "COMMIT" or "ROLLBACK". In php (and where is compatible) I suggest this: //this is php code: $error = false; dbExec("BEGIN"); //I use a switch statement so I can jump out of it with a break at any time switch (1){ case 1: ... $sql = "Insert...."; if (!dbExec($sql)) {$error = true; break;}//was an error?? we jump out from switch ... $sql = "Select ...."; if (!dbExec($sql)) {$error = true; break;} ... $sql = "Update...."; if (!dbExec($sql)) {$error = true; break;} ... }//switch if ($error) dbExec("ROLBACK"); //an error ocured else dbExec("COMMIT");//there was no error Hope this helps. Best regards, Andy. ----- Original Message ----- From: "Stef" To: Sent: Monday, May 10, 2004 4:08 PM Subject: [SQL] Exceptions when 0 rows affected. Hi all, I've been looking on Google,the archives and documentation, but cannot find what I'm looking for. Maybe I've read the answer, but it's still evading me. I'm working with postgres 7.3.4 using the psql client. I want to know if it's possible to raise an error in a transactional BEGIN->END block when e.g. an update or delete statement affects zero rows. I want the entire transaction block to rollback when this happens. I can do it in perl and java , but would in this instance like to load a file with SQL statements using psql -f . Is it possible? Kind Regards Stefan