Thread: BUG #9485: RFE - cycling sequence rollover to do modulo

BUG #9485: RFE - cycling sequence rollover to do modulo

From
Paul.Murray@environment.gov.au
Date:
The following bug has been logged on the website:

Bug reference:      9485
Logged by:          Paul Murray
Email address:      Paul.Murray@environment.gov.au
PostgreSQL version: 9.3.2
Operating system:   OSX
Description:

When a sequence with a cycle does a rollover, it sets itself to its minimum
value.

I would like an option to create a sequence that resets to the minimum value
plus the amount by which the next number exceeded the maximum. Perhaps like
this:

create sequence foo increment 616 min value 0 maxvalue 999 cycle modulo;

This allows me to create a sequence where the generated numbers are not
consecutive, but which will exhaust the number range I have assigned (by
making the increment relatively prime to the number of elements in the
range).

(PS: 616/1000 is, of course, the golden ratio <g>)

Re: BUG #9485: RFE - cycling sequence rollover to do modulo

From
Alvaro Herrera
Date:
Paul.Murray@environment.gov.au wrote:

> When a sequence with a cycle does a rollover, it sets itself to its minimum
> value.
>
> I would like an option to create a sequence that resets to the minimum value
> plus the amount by which the next number exceeded the maximum. Perhaps like
> this:
>
> create sequence foo increment 616 min value 0 maxvalue 999 cycle modulo;

Would this be useful?

http://www.postgresql.org/message-id/CA+U5nMKh+pmbaGUd_x9ev-F5k+whT8HM7wXfkX9ouF=cPkAQEg@mail.gmail.com

You'd have to create a new "sequence access method" that provided the
behavior you want.

I think it'd be interesting to have an implementation of the behavior
you want on top of the proposed patch.

--
Álvaro Herrera                http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services