Best approach for a "gap-less" sequence - Mailing list pgsql-general

From Jorge Godoy
Subject Best approach for a "gap-less" sequence
Date
Msg-id 87u04ic0g2.fsf@ieee.org
Whole thread Raw
Responses Re: Best approach for a "gap-less" sequence  ("chris smith" <dmagick@gmail.com>)
Re: Best approach for a "gap-less" sequence  (Thomas Kellerer <spam_eater@gmx.net>)
Re: Best approach for a "gap-less" sequence  (Jorge Godoy <jgodoy@gmail.com>)
Re: Best approach for a "gap-less" sequence  ("Dawid Kuroczko" <qnex42@gmail.com>)
List pgsql-general
Hi!


I was trying to solve a problem on an old system and realized that there might
be some better approach for doing what I need.

We have some documents that need to be ordered sequentially and without gaps.
I could use a sequence, but if the transaction fails then when I rollback the
sequence will already have been incremented.

So, today I have a control table and I acquire a SHARE ROW EXCLUSIVE lock to
it, read the value, increase it, do what I need and then I COMMIT the
transaction, ensuring that the sequence has no gaps.

Is there a better way to guarantee that there will be no gaps in my sequence
if something goes wrong with my transaction?


--
Jorge Godoy      <jgodoy@gmail.com>

pgsql-general by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Connection string
Next
From: David Fetter
Date:
Subject: Jasper Reports