pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Riccardo G. Facchini <abief_ag_-postgresql@yahoo.com>
Cc: pgsql-sql@postgresql.org, Theodore Petrosky <tedpet5@yahoo.com>
Cc: Andrei Bintintan <klodoma@ar-sd.net>
Cc: sad <sad@bankir.ru>
Subject: Re: A transaction in transaction? Possible?
Date: Wed, 10 Nov 2004 02:53:52 -0700
Message-ID: <20041110095352.GA55504@winnie.fuhr.org> (raw)
In-Reply-To: <20041110084519.10681.qmail@web13902.mail.yahoo.com>
References: <20041110062510.GA54426@winnie.fuhr.org>
	<20041110084519.10681.qmail@web13902.mail.yahoo.com>

On Wed, Nov 10, 2004 at 12:45:19AM -0800, Riccardo G. Facchini wrote:

> Sorry, but I understand that your example is not really about nested
> transactions, but about sequential transactions.

Here's a more elaborate example.  If this doesn't demonstrate the
capability you're looking for, then please provide an example of
what you'd like to do and describe the desired behavior.

CREATE TABLE person (id SERIAL PRIMARY KEY, name TEXT NOT NULL);

BEGIN;
    INSERT INTO person (name) VALUES ('Alice');

    SAVEPOINT s1;
        INSERT INTO person (name) VALUES ('Bob');

	SAVEPOINT s2;
	    INSERT INTO person (name) VALUES ('Charles');

	    SAVEPOINT s3;
	        INSERT INTO person (name) VALUES ('David');
	    ROLLBACK TO s3;

	    INSERT INTO person (name) VALUES ('Edward');
	ROLLBACK TO s2;

        INSERT INTO person (name) VALUES ('Frank');
    RELEASE s1;

    INSERT INTO person (name) VALUES ('George');
COMMIT;

SELECT * FROM person;
 id |  name  
----+--------
  1 | Alice
  2 | Bob
  6 | Frank
  7 | George

If you change "ROLLBACK TO s2" to "RELEASE s2" then you get this:

 id |  name   
----+---------
  1 | Alice
  2 | Bob
  3 | Charles
  5 | Edward
  6 | Frank
  7 | George

If you change "RELEASE s1" to "ROLLBACK TO s1" then you get this:

 id |  name  
----+--------
  1 | Alice
  7 | George

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/



view thread (18+ messages)  latest in thread

Message-ID: <20041110095352.GA55504@winnie.fuhr.org>
Permalink:  ../20041110095352.GA55504@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20041110095352.GA55504@winnie.fuhr.org

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: mike@fuhr.org, abief_ag_-postgresql@yahoo.com, tedpet5@yahoo.com, klodoma@ar-sd.net, sad@bankir.ru
  Subject: Re: A transaction in transaction? Possible?
  In-Reply-To: <20041110095352.GA55504@winnie.fuhr.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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