Received: from localhost (unknown [200.46.208.211]) by mail.postgresql.org (Postfix) with ESMTP id 72E9D635E7D for ; Fri, 31 Jul 2009 15:16:28 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.208.211]) (amavisd-maia, port 10024) with ESMTP id 78521-01-9 for ; Fri, 31 Jul 2009 18:16:15 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from milkno.com (pfeiffer02.nmmn.net [217.114.78.33]) by mail.postgresql.org (Postfix) with ESMTP id 1FD15635289 for ; Fri, 31 Jul 2009 15:12:43 -0300 (ADT) Received: from localhost (localhost [127.0.0.1]) by milkno.com (Postfix) with ESMTP id 12B7E15CC08E; Fri, 31 Jul 2009 20:12:33 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at milkno.com Received: from milkno.com ([127.0.0.1]) by localhost (localhost [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JZbhKE83-1C3; Fri, 31 Jul 2009 20:12:32 +0200 (CEST) Received: from [192.168.178.25] (p54AB8AB0.dip0.t-ipconnect.de [84.171.138.176]) by milkno.com (Postfix) with ESMTPA id E2EC715CC08B; Fri, 31 Jul 2009 20:12:31 +0200 (CEST) Message-ID: <4A733418.6000304@netzmeister-st-pauli.de> Date: Fri, 31 Jul 2009 20:12:40 +0200 From: Andreas Wenk User-Agent: Thunderbird 2.0.0.22 (X11/20090608) MIME-Version: 1.0 To: Jasmin Dizdarevic CC: pgsql-sql@postgresql.org Subject: Re: on error resume next References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=-10 required=5 tests=none X-Spam-Level: X-Archive-Number: 200907/165 X-Sequence-Number: 32906 Jasmin Dizdarevic wrote: > hi, > > can i use savepoints to realize something like "on error resume next"? > > i've got the following situation: > > begin; > 1. create view user001.accounts as select * from base.accounts; > 2. grant select on user001.accounts to loginuser001; > commit; > > begin; > 3. create view user002.accounts as select * from base.accounts; > 4. grant select on user002.accounts to loginuser002; > commit; > > > my goal is to avoid execution stop, if one of the transactions fail. > let's say line 1 throws an error it should go further to line 3. > > any ideas? > > thank you. > > jasmin AFAIK it's not possible. A transaction is kind of a container with a positive or negative result. If one of the queries fails in between a transaction, it will be rolled back after a commit. What you can do with savepoints is the following: usage=# CREATE TABLE test (id serial, content text); usage=# BEGIN; usage=# INSERT INTO test (content) VALUES ('first stuff'); usage=# SAVEPOINT s1; usage=# INSERT INTO test (content) VALUES (); ERROR: syntax error at or near ")" usage=# ROLLBACK TO SAVEPOINT s1; ROLLBACK usage=# SELECT * FROM test; id | content ----+-------------- 1 | first stuff (1 row) usage=# COMMIT; COMMIT usage=# SELECT * FROM test; id | content ----+-------------- 1 | first stuff (1 row) The second INSERT statement fails. If you would go further with insert statements and then fire a COMMIT at the end, nothing would be inserted into the table. But if you fire a ROLLBACK TO SAVEPOINT s1, at least the data of the first INSERT statement are written. So maybe this is a start help for creating some logic to get something like 'on error resume next'. Cheers Andy