From: Jason Earl <jdearl@yahoo.com>
To: Antti Linno <alligator@all.ee>
To: pgsql-sql@postgresql.org
Subject: Re: Birthday search.
Date: Thu, 22 Mar 2001 09:27:26 -0800 (PST)
Message-ID: <20010322172726.3300.qmail@web10003.mail.yahoo.com> (raw)
In-Reply-To: <Pine.LNX.4.04.10103221647520.4786-100000@all.ee>
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@all.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@postgresql.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/
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: jdearl@yahoo.com, alligator@all.ee
Subject: Re: Birthday search.
In-Reply-To: <20010322172726.3300.qmail@web10003.mail.yahoo.com>
References: <Pine.LNX.4.04.10103221647520.4786-100000@all.ee> <20010322172726.3300.qmail@web10003.mail.yahoo.com>
* 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