Re: guaranteeing that a sequence never skips

From: "Scott Marlowe" <smarlowe(at)qwest(dot)net>
To: "David Garamond" <lists(at)zara(dot)6(dot)isreserved(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: guaranteeing that a sequence never skips
Date: 2004-10-03 17:21:38
Message-ID: 1096824098.32732.16.camel@localhost.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Sun, 2004-10-03 at 08:58, David Garamond wrote:
> Am I correct to assume that SERIAL does not guarantee that a sequence
> won't skip (e.g. one successful INSERT gets 32 and the next might be 34)?
>
> Sometimes a business requirement is that a serial sequence never skips,
> e.g. when generating invoice/ticket/formal letter numbers. Would an
> INSERT INTO t (id, ...) VALUES (SELECT MAX(col)+1 FROM t, ...) suffice,
> or must I install a trigger too to do additional checking?

You will have to lock the whole table and your parallel performance will
be poor.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2004-10-03 17:23:01 Re: VACUUM FULL on 24/7 server
Previous Message Greg Sabino Mullane 2004-10-03 16:45:46 GnuPG / PGP signed checksums for PostgreSQL 7.4.5, 7.4.4, 7.3.7, 7.3.6, 7.3.5. 7.2.5