Re: independent sequence for each month

Поиск
Список
Период
Сортировка
От Bruno Wolff III
Тема Re: independent sequence for each month
Дата
Msg-id 20030814141200.GG27870@wolff.to
обсуждение исходный текст
Ответ на independent sequence for each month  (Tomasz Myrta <jasiek@klaster.net>)
Список pgsql-sql
On Thu, Aug 14, 2003 at 08:18:46 +0200, Tomasz Myrta <jasiek@klaster.net> wrote:
> Hi
> I have to generate unique numbers starting from 1 every month. I can't 
> reset sequence on last day of month, because sometimes I have to insert 
> some future or past values. I thought I can create independent sequence 
> for each month, but it doesn't sound elegant.

If you are restarting from 1 each month, I suspect that you also want
consecutive nmumbers without any gaps. If so, then using sequences
may not work for you.

If your server isn't heavily loaded you can lock the table and select
the highest number used in the current month (using coalesce to change
null to 0) and add 1 to it in your insert statement.

Another option is if the numbers only appear on reports and are not used
in the database, is to have the application generate them. If the reports
are just listings of the complete list of monthly events this will probably
be easy.


В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Timezone troubles
Следующее
От: Christoph Haller
Дата:
Сообщение: Re: Changing data type must recreate all views?