Re: Restart a sequence regularly - Mailing list pgsql-general

From Harald Fuchs
Subject Re: Restart a sequence regularly
Date
Msg-id puy7cqziyb.fsf@srv.protecting.net
Whole thread Raw
In response to Restart a sequence regularly  ("Kathy Lo" <kathy.lo.ky@gmail.com>)
List pgsql-general
In article <47453419.1050901@archonet.com>,
Richard Huxton <dev@archonet.com> writes:

> Kathy Lo wrote:
>> On 11/21/07, Richard Huxton <dev@archonet.com> wrote:

>>> You probably shouldn't attach any meaning to the numbers from a sequence
>>> - they're just guaranteed to be unique, nothing else.

> What you say here contradicts the following.

>> Actually, the sequence is formed by 4-digit of year and 6-digit of
>> sequence.

> So you *are* attaching significance to the number (by adding the
> current year to the front of it).

> Don't block users - have multiple sequences. If you define
> my_seq_2007, my_seq_2008, my_seq_2009 etc and then wrap access to them
> in a function you can EXTRACT() the year from the CURRENT_DATE and use
> that to form your per-year unique value.

Since sequences don't guarantee consecutivity anyway, why not just use
one sequence and prepend the year, e.g. by a view?

pgsql-general by date:

Previous
From: Simon Riggs
Date:
Subject: Re: Read-only availability of a standby server?
Next
From: Oleg Bartunov
Date:
Subject: Re: EAV or not to EAV?