Sequences change in a rolled-back transactions - Mailing list pgsql-general

From Erwin Moller
Subject Sequences change in a rolled-back transactions
Date
Msg-id 49B53245.5080102@darwine.nl
Whole thread Raw
Responses Re: Sequences change in a rolled-back transactions
List 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

pgsql-general by date:

Previous
From: justin
Date:
Subject: Re: mdf
Next
From: Alvaro Herrera
Date:
Subject: Re: Sequences change in a rolled-back transactions