Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id CFAAA634D84 for ; Fri, 31 Jul 2009 15:52:35 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 58724-04 for ; Fri, 31 Jul 2009 18:52:25 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.153]) by mail.postgresql.org (Postfix) with ESMTP id E7E436353E0 for ; Fri, 31 Jul 2009 15:52:17 -0300 (ADT) Received: by fg-out-1718.google.com with SMTP id 13so134288fge.0 for ; Fri, 31 Jul 2009 11:52:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=Wi4+tqJOz9/+7FHnxpbqLEjdDL+TOq0jljY7uWdps3M=; b=EXlryuMGoC1m69s0U/+bSAC2OW4huaK56KOXbSDTXj/K5uphVrMSI/zKGYLK1FB/UI KQg8JqukMYDigxRCjbi3K3DWlkEsHAVqJ8goFp7AfJnRs7KNimqaFDKPgk5remDEc8tP ege05/kWBLPS4EiJzaGYC0STuNWzsSyS2tj/s= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=On79YfNv95+bYi4yXkoZD656mfhEVn9CEpjU2SdCnN7pvlIAs7doDg295ftNBlND1w jktppEWJGJK2steFejlpfmnU4XtCnbldKmt96AFPjYouHek6VKl+5Dj7lQbQV5cLkbkb C0R2XBx62h8WY8HAQlLI/UJYkX4PHsZVYW8SU= MIME-Version: 1.0 Received: by 10.86.31.14 with SMTP id e14mr952887fge.79.1249066336111; Fri, 31 Jul 2009 11:52:16 -0700 (PDT) In-Reply-To: <4A733418.6000304@netzmeister-st-pauli.de> References: <4A733418.6000304@netzmeister-st-pauli.de> Date: Fri, 31 Jul 2009 20:52:16 +0200 Message-ID: Subject: Re: on error resume next From: Jasmin Dizdarevic To: Andreas Wenk Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=000e0cd250f043cbdd047004eb31 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.001 tagged_above=-10 required=5 tests=HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200907/166 X-Sequence-Number: 32907 --000e0cd250f043cbdd047004eb31 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Hi, that's not really that what i need. I think i will solve it on client side. thank you. jasmin 2009/7/31 Andreas Wenk > 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 > > > > --000e0cd250f043cbdd047004eb31 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi,
=A0
that's not really that what i need. I think i will solve it on cli= ent side.
=A0
thank you.
jasmin

2009/7/31 Andreas Wenk <a.wenk@netzmeister-st-pauli.= de>
Jasmin Dizdarevic wrote:
hi,
=A0can i use savepoints t= o realize something like "on error resume next"?
=A0i've g= ot the following situation:
=A0begin;
1. create view user001.accounts as select * from base.accounts= ;
2. grant select on user001.accounts to loginuser001;
commit;
=A0= begin;
3. create view user002.accounts as select * from base.accounts; 4. grant select on user002.accounts to loginuser002;
commit;
=A0=A0my= goal is to avoid execution stop, if one of the transactions fail.
let&#= 39;s say line 1 throws an error it should go further to line 3.
=A0any i= deas?
=A0thank you.
=A0jasmin

AFAIK it's n= ot possible. A transaction is kind of a container with a positive or negati= ve 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 followi= ng:

usage=3D# CREATE TABLE test (id serial, content text);
usage=3D# BEG= IN;
usage=3D# INSERT INTO test (content) VALUES ('first stuff');=
usage=3D# SAVEPOINT s1;
usage=3D# INSERT INTO test (content) VALUES = ();
ERROR: =A0syntax error at or near ")"
usage=3D# ROLLBACK TO SA= VEPOINT s1;
ROLLBACK
usage=3D# SELECT * FROM test;
=A0id | =A0 con= tent
----+--------------
=A01 | first stuff
(1 row)

usage= =3D# COMMIT;
COMMIT
usage=3D# SELECT * FROM test;
=A0id | =A0 content
----+----= ----------
=A01 | first stuff
(1 row)

The second INSERT statem= ent fails. If you would go further with insert statements and then fire a C= OMMIT 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 statemen= t are written.

So maybe this is a start help for creating some logic to get something = like 'on error resume next'.

Cheers

Andy


<= br>

--000e0cd250f043cbdd047004eb31--