Skip site navigation (1) Skip section navigation (2)

Re: How to create "auto-increment" field WITHOUT a sequence object?

From: "A(dot)M(dot)" <agentm(at)themactionfaction(dot)com>
To: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?
Date: 2011-06-30 18:55:30
Message-ID: CC059AA0-B030-46F6-8A70-E9B7B7C99FAB@themactionfaction.com (view raw or flat)
Thread:
Lists: pgsql-general
On Jun 30, 2011, at 2:40 PM, Dmitry Koterov wrote:

> Hello.
> 
> I need to create an auto-increment field on a table WITHOUT using sequences:

This problem pops up a lot for invoice sequence numbers for the tax office and related cases. (Search for "gapless sequence".) 

Since the numbers are really only needed for an external system (as you mention), then it may make sense to generate the gapless IDs when necessary and map the generated IDs to the rows later. The drawback is that some rows in the table will not have the gapless ID until the batch job is run, but all rows will still be addressable by the real sequence ID.

Cheers,
M



In response to

Responses

pgsql-general by date

Next:From: Dmitry KoterovDate: 2011-06-30 19:01:13
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?
Previous:From: salah jubehDate: 2011-06-30 18:51:19
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group