Re: Restart a sequence regularly

From: Harald Fuchs <hf0217x(at)protecting(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Restart a sequence regularly
Date: 2007-11-22 10:13:32
Message-ID: puy7cqziyb.fsf@srv.protecting.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

In article <47453419(dot)1050901(at)archonet(dot)com>,
Richard Huxton <dev(at)archonet(dot)com> writes:

> Kathy Lo wrote:
>> On 11/21/07, Richard Huxton <dev(at)archonet(dot)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?

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Oleg Bartunov 2007-11-22 10:57:34 Re: EAV or not to EAV?
Previous Message Simon Riggs 2007-11-22 09:47:02 Re: Read-only availability of a standby server?