pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Birthday search.
2+ messages / 2 participants
[nested] [flat]

* Birthday search.
@ 2001-03-22 14:50  Antti Linno <alligator@all.ee>
  0 siblings, 1 reply; 2+ messages in thread

From: Antti Linno @ 2001-03-22 14:50 UTC (permalink / raw)
  To: pgsql-sql

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





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Birthday search.
@ 2001-03-22 17:27  Jason Earl <jdearl@yahoo.com>
  parent: Antti Linno <alligator@all.ee>
  0 siblings, 0 replies; 2+ messages in thread

From: Jason Earl @ 2001-03-22 17:27 UTC (permalink / raw)
  To: Antti Linno <alligator@all.ee>; 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@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/



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2001-03-22 17:27 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-03-22 14:50 Birthday search. Antti Linno <alligator@all.ee>
2001-03-22 17:27 ` Jason Earl <jdearl@yahoo.com>

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