Re: How to create "auto-increment" field WITHOUT a sequence object? - Mailing list pgsql-general

From Chris Travers
Subject Re: How to create "auto-increment" field WITHOUT a sequence object?
Date
Msg-id CAKt_Zfu4padtk21KWKM8cPgnnf9KU621YVP-9+Mkws0zKoKhcg@mail.gmail.com
Whole thread Raw
In response to Re: How to create "auto-increment" field WITHOUT a sequence object?  (Ireneusz Pluta <ipluta@wp.pl>)
Responses Re: How to create "auto-increment" field WITHOUT a sequence object?  (Vincent de Phily <vincent.dephily@mobile-devices.fr>)
List pgsql-general
On Sun, Jul 3, 2011 at 7:25 AM, Ireneusz Pluta <ipluta@wp.pl> wrote:

> You may use dense_rank() (or even rank()) window function to map your
> sequence-with-gaps to a no-gap-id which will be used for exports.
>

The typical case where gapless numbering comes up is something like this:

In Greece, you go get invoice paper from the tax office which is
numbered in sequence and the government gets a list of the invoice
forms you have purchased.  You then print the invoices on those paper
forms, and must number the invoices sequentially and without gaps.  In
the case of an audit, all paper forms obtained must be accounted for
as must all gaps in numbering.  You MUST be able to connect each
sequential invoice number (internally generated) to each invoice form
(numbered at the tax office).

In this case you really have no choice but to lock some records,
generate a new gapless id, and save/print it.  Naturally this causes
the sorts of problems mentioned.

Best Wishes,
Chris Travers

pgsql-general by date:

Previous
From: Ireneusz Pluta
Date:
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?
Next
From: Daron Ryan
Date:
Subject: Select from Java Strings