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

From: Chris Travers <chris(dot)travers(at)gmail(dot)com>
To:
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: How to create "auto-increment" field WITHOUT a sequence object?
Date: 2011-07-01 00:57:38
Message-ID: BANLkTi=5067Y=92J+UJiUG2ZTmWhfrTVeg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Having done gapless numbering for some users of accounting software,
there are two suggestions I would make.

The first is that any sort of gapless numbering inherently runs into
scalability. You HAVE to lock relevant records, and this means that
only one insert can run at a time, and it must commit before the next
insert can run. This means you have to keep your transactions short
and predictable in terms of table order. The suggestion of using for
update is a good one, but it doesn't entirely get rid of the problem,
which is inherent in ensuring gapless numbering in a system with
concurrent transactions.

The second is that you absolutely should use this approach as rarely
as you can get away with. If it isn't required, don't use it!

Best Wishes,
Chris Travers

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message gnuoytr 2011-07-01 01:00:13 Re: Contrib source
Previous Message Casey Havenor 2011-06-30 23:43:32 Re: Inheritence issue scheme advice?