Re: Best approach for a "gap-less" sequence - Mailing list pgsql-general

From Harald Fuchs
Subject Re: Best approach for a "gap-less" sequence
Date
Msg-id pu7j1bf4tb.fsf@srv.protecting.net
Whole thread Raw
In response to Best approach for a "gap-less" sequence  (Jorge Godoy <jgodoy@gmail.com>)
Responses Re: Best approach for a "gap-less" sequence  (Jorge Godoy <jgodoy@gmail.com>)
List pgsql-general
In article <87zme7uvcn.fsf@gmail.com>,
Jorge Godoy <jgodoy@gmail.com> writes:

> Harald Fuchs <hf0731x@protecting.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.

pgsql-general by date:

Previous
From: Harald Fuchs
Date:
Subject: Re: Best approach for a "gap-less" sequence
Next
From: Harald Fuchs
Date:
Subject: Re: Best approach for a "gap-less" sequence