guaranteeing that a sequence never skips

From: David Garamond <lists(at)zara(dot)6(dot)isreserved(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: guaranteeing that a sequence never skips
Date: 2004-10-03 14:58:26
Message-ID: 41601392.5000800@zara.6.isreserved.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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?

--
dave

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alvaro Herrera 2004-10-03 15:18:33 Re: sequence rename?
Previous Message Mike Rylander 2004-10-03 14:55:14 Re: Query problem...