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

From Christian Kratzer
Subject Re: Best approach for a "gap-less" sequence
Date
Msg-id 20060813171538.S59185@vesihiisi.cksoft.de
Whole thread Raw
In response to Re: Best approach for a "gap-less" sequence  ("chris smith" <dmagick@gmail.com>)
Responses Re: Best approach for a "gap-less" sequence  (Jorge Godoy <godoy@ieee.org>)
List pgsql-general
Hi,

On Sat, 12 Aug 2006, chris smith wrote:

> On 8/12/06, Jorge Godoy <jgodoy@gmail.com> wrote:
<snipp/>
>> Is there a better way to guarantee that there will be no gaps in my
>> sequence
>> if something goes wrong with my transaction?
>
> Why does it matter?
>
> I assume there is a reason you need it like this..

For example german tax law requires invoices to be numbered
sequentially without gaps.  This is supposed to make it harder
to cheat on VAT.

You cannot just drop an invoice as that would leave a gap.  Tax
inspectors will search for gaps and query to whatever invoice
is missing from records.

I could not care less about gaps in surrogate keys but this
kind of stuff is an external requirement.

Theres propably not much choice on how to implement something
like this but to just store the last assigned number in some row.

I would at least try to assign multiple such numbers in batches
to mimize contention on the row you store the counter in.

Greetings
Christian

--
Christian Kratzer                       ck@cksoft.de
CK Software GmbH                        http://www.cksoft.de/
Phone: +49 7452 889 135                 Fax: +49 7452 889 136

pgsql-general by date:

Previous
From: Richard Broersma Jr
Date:
Subject: Re: Connection string
Next
From: Jorge Godoy
Date:
Subject: Re: Best approach for a "gap-less" sequence