pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
on error resume next
3+ messages / 2 participants
[nested] [flat]

* on error resume next
@ 2009-07-31 15:24 Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  2009-07-31 18:12 ` Re: on error resume next Andreas Wenk <a.wenk@netzmeister-st-pauli.de>
  0 siblings, 1 reply; 3+ messages in thread

From: Jasmin Dizdarevic @ 2009-07-31 15:24 UTC (permalink / raw)
  To: pgsql-sql

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

^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: on error resume next
  2009-07-31 15:24 on error resume next Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
@ 2009-07-31 18:12 ` Andreas Wenk <a.wenk@netzmeister-st-pauli.de>
  2009-07-31 18:52   ` Re: on error resume next Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  0 siblings, 1 reply; 3+ messages in thread

From: Andreas Wenk @ 2009-07-31 18:12 UTC (permalink / raw)
  To: Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>; +Cc: pgsql-sql

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






^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: on error resume next
  2009-07-31 15:24 on error resume next Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  2009-07-31 18:12 ` Re: on error resume next Andreas Wenk <a.wenk@netzmeister-st-pauli.de>
@ 2009-07-31 18:52   ` Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
  0 siblings, 0 replies; 3+ messages in thread

From: Jasmin Dizdarevic @ 2009-07-31 18:52 UTC (permalink / raw)
  To: Andreas Wenk <a.wenk@netzmeister-st-pauli.de>; +Cc: pgsql-sql

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 <a.wenk@netzmeister-st-pauli.de>

>  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
>
>
>
>

^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2009-07-31 18:52 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-07-31 15:24 on error resume next Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>
2009-07-31 18:12 ` Andreas Wenk <a.wenk@netzmeister-st-pauli.de>
2009-07-31 18:52   ` Jasmin Dizdarevic <jasmin.dizdarevic@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox