Re: PL/PgSQL: EXIT USING ROLLBACK

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Marko Tiikkaja <marko(at)joh(dot)to>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: PL/PgSQL: EXIT USING ROLLBACK
Date: 2014-07-26 18:22:20
Message-ID: 32224.1406398940@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Marko Tiikkaja <marko(at)joh(dot)to> writes:
> Hello,
> Today I'd like to present a way to get rid of code like this:

> $$
> BEGIN

> BEGIN
> INSERT INTO foo VALUES (1);
> -- run some tests/checks/whatever
> RAISE EXCEPTION 'OK';
> EXCEPTION WHEN raise_exception THEN
> IF SQLERRM <> 'OK' THEN
> RAISE;
> END IF;
> END;

> RETURN 'success';
> END
> $$

> And replace it with code like this:

> $$
> BEGIN

> <<testsomething>>
> BEGIN
> INSERT INTO foo VALUES (1);
> -- run some tests/checks/whatever
> EXIT USING ROLLBACK testsomething;
> EXCEPTION WHEN others THEN
> RAISE;
> END;

> RETURN 'success';
> END
> $$

Somehow I'm failing to see that as much of an improvement;
in fact, it's probably less clear than before. I don't much
care for the idea that EXIT should take on some transaction-control
properties instead of being a simple transfer of control.
In particular, what happens if someone attaches USING ROLLBACK
to an EXIT that does not lead from inside to outside a BEGIN/EXCEPTION
block?

regards, tom lane

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Andres Freund 2014-07-26 18:22:21 Re: building pdfs
Previous Message Andres Freund 2014-07-26 18:20:05 Re: [RFC] Should smgrtruncate() avoid sending sinval message for temp relations