pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Tomasz Myrta <jasiek@klaster.net>
Cc: PGSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: independent sequence for each month
Date: Thu, 14 Aug 2003 09:12:00 -0500
Message-ID: <20030814141200.GG27870@wolff.to> (raw)
In-Reply-To: <3F3B29C6.6050101@klaster.net>
References: <3F3B29C6.6050101@klaster.net>

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.



view thread (2+ messages)

Message-ID: <20030814141200.GG27870@wolff.to>
Permalink:  ../20030814141200.GG27870@wolff.to/
Also on:    postgresql.org/message-id/20030814141200.GG27870@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, jasiek@klaster.net
  Subject: Re: independent sequence for each month
  In-Reply-To: <20030814141200.GG27870@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

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