Re: Restart a sequence regularly
От | Harald Fuchs |
---|---|
Тема | Re: Restart a sequence regularly |
Дата | |
Msg-id | puy7cqziyb.fsf@srv.protecting.net обсуждение исходный текст |
Ответ на | Restart a sequence regularly ("Kathy Lo" <kathy.lo.ky@gmail.com>) |
Список | 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 по дате отправления: