Sequences change in a rolled-back transactions

From: Erwin Moller <erwin(at)darwine(dot)nl>
To: pgsql-general(at)postgresql(dot)org
Subject: Sequences change in a rolled-back transactions
Date: 2009-03-09 15:14:13
Message-ID: 49B53245.5080102@darwine.nl
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi group,

I just noticed getting the next number of a sequence doesn't respect a
transaction.
Here is an example:
=======================================================
erwin=# SELECT nextval('tblofferlabel_offerlabelid_seq'::regclass) as
nextofferlabelid;
nextofferlabelid
------------------
87
(1 row)

erwin=# start transaction;
START TRANSACTION
erwin=# SELECT nextval('tblofferlabel_offerlabelid_seq'::regclass) as
nextofferlabelid;
nextofferlabelid
------------------
88
(1 row)

erwin=# SELECT nextval('tblofferlabel_offerlabelid_seq'::regclass) as
nextofferlabelid;
nextofferlabelid
------------------
89
(1 row)

# rollback;
ROLLBACK

erwin=# SELECT nextval('tblofferlabel_offerlabelid_seq'::regclass) as
nextofferlabelid;
nextofferlabelid
------------------
90
=======================================================
As you can see the sequence just counts on outside the transaction.

I thought a transaction that is rolled back, rolls back *everything*
done in that transaction.
Appearantly sequences are not included.

It is no big deal, since I can easily code this differently, but I was
unpleasantly surprised. :-/
Can anybody comment on this behaviour? Am I missing something?

Thanks!

Regards,
Erwin Moller

Responses

Browse pgsql-general by date

  From Date Subject
Next Message justin 2009-03-09 15:15:40 Re: mdf
Previous Message Ary Pezo Silvano 2009-03-09 14:53:10 Re: mdf