Re: SAVEPOINT SQL conformance - Mailing list pgsql-hackers

From Oliver Jowett
Subject Re: SAVEPOINT SQL conformance
Date
Msg-id 414CAB84.2090102@opencloud.com
Whole thread Raw
In response to SAVEPOINT SQL conformance  ("Michael Paesold" <mpaesold@gmx.at>)
List pgsql-hackers
Michael Paesold wrote:

> BEGIN;
> SAVEPOINT a;
> INSERT INTO ...
> SAVEPOINT a;
> INSERT INTO ...
> SAVEPOINT a;
> ...
> (encountering an error it would just ROLLBACK TO a;)
> 
> According to the standard this is exactly the same as:
> 
> BEGIN;
> SAVEPOINT a;
> INSERT INTO ...
> RELEASE SAVEPOINT a;
> SAVEPOINT a;
> INSERT INTO ...

While that's true in this particular case, you can't do that 
transformation in the general case. Consider:

BEGIN
SAVEPOINT a -- work
SAVEPOINT b -- work
SAVEPOINT a -- work
ROLLBACK TO b -- work

This is valid: the standard says that the second "SAVEPOINT a" destroys 
and recreates the savepoint "a", but doesn't say that it destroys 
intervening savepoints. In contrast, RELEASE SAVEPOINT explicitly says 
that it destroys the specified savepoint and all savepoints established 
since the specified savepoint.

If you converted the second "SAVEPOINT a" into "RELEASE SAVEPOINT a; 
SAVEPOINT a" then savepoint "b" would be incorrectly destroyed.

It'd work for the (common?) case where there are no intervening 
savepoints, though.

-O


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: SAVEPOINT SQL conformance
Next
From: "Michael Paesold"
Date:
Subject: Re: SAVEPOINT SQL conformance