Best approach for a "gap-less" sequence

From: Jorge Godoy <jgodoy(at)gmail(dot)com>
To: PostgreSQL General ML <pgsql-general(at)postgresql(dot)org>
Subject: Best approach for a "gap-less" sequence
Date: 2006-08-11 23:33:17
Message-ID: 87u04ic0g2.fsf@ieee.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmail(dot)com>

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Richard Broersma Jr 2006-08-11 23:44:49 Re: Unable to connect to PostgreSQL 8 from PGAdmin III
Previous Message Michael Fuhr 2006-08-11 22:40:36 Re: Connection string