Re: Sequences change in a rolled-back transactions

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

Alvaro Herrera schreef:
> Erwin Moller wrote:
>
>
>> I thought a transaction that is rolled back, rolls back *everything*
>> done in that transaction.
>> Appearantly sequences are not included.
>>
>
>
Hi Alvaro,

Thanks for your reply.

> Yes. This is actually a desirable property, because it allows sequences
> to work fine in concurrent scenarios (which are, after all, the whole
> point of sequences).
>
Ok.
I think I understand what you mean.

Scenario:
1) I start my transaction in which I call nextval(etc.etc).
2) Some other process/person has to wait for that transaction to end to
get its own new sequencenumber.

That would surely be not desirable now I think of it. :-)
So Postgres developers decided to hand them out immediately, since
nothing of real value has changed in the db, and they are just
incremental numbers.

> If you actually need an incremental number with no gaps (which is rare
> but not unseen), you need to use some other mechanism, which will
> probably involve a lock to prevent concurrency.
>
No, I don't need gap-less numbering.
In (almost all) situations I use sequences it is simply to generate
unique PKs for some table, so I don't care for gaps in the numbering.

I just thought I hitted some stange bug. ;-)

Thanks for your time.

Regards,
Erwin Moller

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Craig Ringer 2009-03-09 15:44:55 Re: Sequences change in a rolled-back transactions
Previous Message Alvaro Herrera 2009-03-09 15:25:55 Re: Sequences change in a rolled-back transactions