pg.ddx.io pgsql-sql@postgresql.org mailing list archive
help / color / mirror / Atom feedindependent sequence for each month
2+ messages / 2 participants
[nested] [flat]
* independent sequence for each month
@ 2003-08-14 06:18 Tomasz Myrta <jasiek@klaster.net>
0 siblings, 1 reply; 2+ messages in thread
From: Tomasz Myrta @ 2003-08-14 06:18 UTC (permalink / raw)
To: pgsql-sql
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.
Regards,
Tomasz Myrta
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: independent sequence for each month
@ 2003-08-14 14:12 Bruno Wolff III <bruno@wolff.to>
parent: Tomasz Myrta <jasiek@klaster.net>
0 siblings, 0 replies; 2+ messages in thread
From: Bruno Wolff III @ 2003-08-14 14:12 UTC (permalink / raw)
To: Tomasz Myrta <jasiek@klaster.net>; +Cc: 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.
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2003-08-14 14:12 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2003-08-14 06:18 independent sequence for each month Tomasz Myrta <jasiek@klaster.net>
2003-08-14 14:12 ` Bruno Wolff III <bruno@wolff.to>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox