Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id E29F12E004E for ; Sun, 4 May 2008 13:11:29 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 35027-02 for ; Sun, 4 May 2008 13:11:25 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from lists.commandprompt.com (host-159.commandprompt.net [207.173.203.159]) by developer.postgresql.org (Postfix) with ESMTP id D33B52E0038 for ; Sun, 4 May 2008 13:11:25 -0300 (ADT) Received: from [192.168.1.226] (or-69-34-217-90.sta.embarqhsd.net [69.34.217.90]) (authenticated bits=0) by lists.commandprompt.com (8.13.8/8.13.8) with ESMTP id m44GCC7x028912 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO); Sun, 4 May 2008 09:12:13 -0700 Message-ID: <481DE036.90706@commandprompt.com> Date: Sun, 04 May 2008 09:11:34 -0700 From: "Joshua D. Drake" Organization: Command Prompt, Inc. User-Agent: Thunderbird 2.0.0.14 (Windows/20080421) MIME-Version: 1.0 To: Hannes Dorbath CC: pgsql-performance@postgresql.org Subject: Re: Fastest way / best practice to calculate "next birthdays" References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Greylist: Sender succeeded SMTP AUTH, not delayed by milter-greylist-4.0 (lists.commandprompt.com [207.173.203.159]); Sun, 04 May 2008 09:12:13 -0700 (PDT) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200805/46 X-Sequence-Number: 30014 Hannes Dorbath wrote: > The subject basically says it all, I'm looking for the fastest > (indexable) way to calculate the next birthdays relative to NOW() from a > dataset of about 1 million users. > > I'm currently using a function based index, but leap year handling / > mapping February 29 to February 28 gives me some headaches. > > Is there any best practice to do that in PostgreSQL? postgres=# SELECT current_date|| ' a ' || to_char(current_date, 'Day'), current_date + '1 Year'::interval || ' a ' || to_char(current_date + '1 Year'::interval, 'Day') as next_birthday; ?column? | next_birthday ------------------------+--------------------------------- 2008-05-04 a Sunday | 2009-05-04 00:00:00 a Monday ? Sincerely, Joshua D. Drake