Re: savepoint improvements

From: Dennis Bjorklund <db(at)zigo(dot)dhs(dot)org>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: PostgreSQL-development <pgsql-hackers(at)postgresql(dot)org>
Subject: Re: savepoint improvements
Date: 2007-01-20 05:26:33
Message-ID: 45B1A809.2070003@zigo.dhs.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Merlin Moncure skrev:

> The missing piece of the puzzle is the ability to recover a failed
> transaction without issuing a full commit/rollback. This could be a
> new flavor of the savepoint command, commit command, or a new command.
> As a bonus, upon recovering the transaction you could snap an sql
> statement...this would be great for scripting:
>
> BEGIN;
> SAVEPOINT X;
> COMMIT ON ERRORS SELECT FOO();
>
> --or--
>
> BEGIN;
> SAVEPOINT x;
> SAVEPOINT y ON ERRORS SELECT FOO; -- (or ROLLBACK TO SAVEPOINT x);
> COMMIT;
>
> comments? fast track to todo list? :-)

Isn't the problem that you try to use psql for scripting and it doesn't
have usual scripting power like branching (if) or looping (while,for)
that most scripting languages have. If there was say an \if command in
psql you could do things like this:

BEGIN;

INSERT INTO foo VALUES (42);

SAVEPOINT X;
INSERT INTO foo VALUES (NULL);

\if errorcode > 0
ROLLBACK TO SAVEPOINT X;

INSERT INTO foo VALUES (666);
\endif

COMMIT;

I'm not sure you want to extend psql to be a full scripting engine, but
maybe. It would be useful to me if it had an \if command like above. An
other alternative is to use some other language to write scripts in that
already have branching, looping, expression evaluation and what else.

/Dennis

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Tom Lane 2007-01-20 07:05:47 Re: Planning aggregates which require sorted or distinct
Previous Message Tom Lane 2007-01-20 05:03:01 Re: BUG #2907: pg_get_serial_sequence quoting