Re: Birthday search.

From: Jason Earl <jdearl(at)yahoo(dot)com>
To: Antti Linno <alligator(at)all(dot)ee>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Birthday search.
Date: 2001-03-22 17:27:26
Message-ID: 20010322172726.3300.qmail@web10003.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Here's an example of something that works with some of
the data that I have lying around. Replace exit_dt
with "birthday" (or whatever you have named the field
that holds the birthday information) and replace
ticket_no with name (or whatever) and you should be on
the right track.

SELECT exit_dt, ticket_no FROM tscales
WHERE (
date_part('month', exit_dt) > 4 AND
date_part('month', exit_dt) < 12)
OR (
date_part('month', exit_dt) = 4 AND
date_part('day', exit_dt) >= 15
)
OR (
date_part('month', exit_dt) = 12 AND
date_part('day', exit_dt) <= 20)
ORDER BY exit_dt;

I don't consider myself enough of a SQL guru to know
if this is the "correct" way to do this, but this
query selects some 21000 records out of a 120000
record table on my desktop test machine (PII 400 96M
Ram standard IDE hard drive running Linux) without any
indexes on exit_dt in a couple of seconds.

For more information check out the user guide section
on date/time functions. It is quite interesting. The
extract function would have served as well, but it
requires more typing.

Jason

--- Antti Linno <alligator(at)all(dot)ee> wrote:
> I have a table with personal data, including date of
> birth in date format.
> What i need is a select that searches birthdays in
> certain range.
> E.g. I need to find all birthdays starting from
> 15.april until 20th
> december. As you all understand, year doesn't matter
> :P
> Any simple and elegant solutions to it?
>
> Greetings,
> Antti
>
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please
> send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org
> so that your
> message can get through to the mailing list cleanly

__________________________________________________
Do You Yahoo!?
Get email at your own domain with Yahoo! Mail.
http://personal.mail.yahoo.com/

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Stephan Szabo 2001-03-22 17:29:04 Re: CHAR or VARCHAR
Previous Message Christof Glaser 2001-03-22 17:16:47 Re: Foreign key referencing subclasses.