X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id 4FB37D1F55D for ; Thu, 14 Aug 2003 14:14:29 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 31559-10 for ; Thu, 14 Aug 2003 11:12:54 -0300 (ADT) Received: from wolff.to (wolff.to [66.93.249.74]) by svr1.postgresql.org (Postfix) with SMTP id 2BEFED1F622 for ; Thu, 14 Aug 2003 11:06:24 -0300 (ADT) Received: (qmail 31686 invoked by uid 500); 14 Aug 2003 14:12:00 -0000 Date: Thu, 14 Aug 2003 09:12:00 -0500 From: Bruno Wolff III To: Tomasz Myrta Cc: PGSQL-SQL Subject: Re: independent sequence for each month Message-ID: <20030814141200.GG27870@wolff.to> Mail-Followup-To: Tomasz Myrta , PGSQL-SQL References: <3F3B29C6.6050101@klaster.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3F3B29C6.6050101@klaster.net> User-Agent: Mutt/1.5.4i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/174 X-Sequence-Number: 14790 On Thu, Aug 14, 2003 at 08:18:46 +0200, Tomasz Myrta 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.