Re: Best approach for a "gap-less" sequence

From: Harald Fuchs <hf0731x(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Best approach for a "gap-less" sequence
Date: 2006-08-14 20:19:44
Message-ID: pu7j1bf4tb.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <87zme7uvcn(dot)fsf(at)gmail(dot)com>,
Jorge Godoy <jgodoy(at)gmail(dot)com> writes:

> Harald Fuchs <hf0731x(at)protecting(dot)net> writes:
>> Why putting gapless numbers into the database at all? Just calculate them at
>> query time.

> And how would you retrieve the record that corresponds to invoice number
> #16355, for example? Recalculating few records is fine, but millions of them
> everytime you need to recover some of those is something that doesn't look
> efficient to me...

This would be

SELECT whatever
FROM tbl
ORDER BY id
LIMIT 1
OFFSET 16355 -1

Since id is the primary key, this can use an index scan.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Harald Fuchs 2006-08-14 20:23:32 Re: Best approach for a "gap-less" sequence
Previous Message Harald Fuchs 2006-08-14 20:12:08 Re: Best approach for a "gap-less" sequence