Re: Fastest way / best practice to calculate "next birthdays"

From: Jim Nasby <Jim(dot)Nasby(at)BlueTreble(dot)com>
To: Bosco Rama <postgres(at)boscorama(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "er(dot)tejaspatel88(at)gmail(dot)com" <er(dot)tejaspatel88(at)gmail(dot)com>
Cc: "pgsql-performance(at)postgresql(dot)org" <pgsql-performance(at)postgresql(dot)org>
Subject: Re: Fastest way / best practice to calculate "next birthdays"
Date: 2015-05-22 21:23:19
Message-ID: 555F9E47.5020003@BlueTreble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

On 5/21/15 11:15 AM, Bosco Rama wrote:
> You could probably make some of that into a function that accepts a
> timestamptz and generates the two days.

You'll be better off if instead of 2 days it gives you a daterange:
http://www.postgresql.org/docs/9.4/static/rangetypes.html

I don't know about the exact ISO details, but your approach is the
correct one: find the date that the current week started on and then
build a range of [week start, week start + 7 days).

Also, note the use of [ vs ). That is the ONLY correct way to do this if
you're comparing to a timestamp.
--
Jim Nasby, Data Architect, Blue Treble Consulting
Data in Trouble? Get it in Treble! http://BlueTreble.com

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Dave Johansen 2015-05-22 22:27:29 MAX() and multi-column index on a partitioned table?
Previous Message Jim Nasby 2015-05-22 21:17:44 Re: How to clean/truncate / VACUUM FULL pg_largeobject without (much) downtime?