Re: SELECTing on age - Mailing list pgsql-general

From Kall, Bruce A.
Subject Re: SELECTing on age
Date
Msg-id 41BE0682.9070001@mayo.edu
Whole thread Raw
In response to Re: disabling OIDs?  ("Mark Dexter" <MDEXTER@dexterchaney.com>)
Responses Re: SELECTing on age  (Scott Marlowe <smarlowe@g2switchworks.com>)
increasing max_connections on freebsd  (Hengki Suhartoyo <hengman03@yahoo.com>)
List pgsql-general
I'm attempting to select records from my postgresql database using php
based on whether someone is at least 17 years old on the date of a
particular visit.

My sql is:

$db_sql = "SELECT * from list WHERE ((visit_date - birth_date) >= 17)'"
$db_result = db_exec($db_sql)
$num = pg_num_rows($db_result);
for($i = 0; $i < $num; $i++)
   {
   $data = pg_num_rows($db_result,$i)
   $visit_date = $data["visit_date"];
   $birth_date = $data["birth_date"];
   echo "Visit date[$visit_date]  Birth date[$birth_date]";
   }

The problem I'm having is that the the query is returning results for
some people with ages < 17 (most of them are correct, just a couple of
incorrect ones interspersed with the correct ones that are over 17)?

For example, my output contains:

Visit date[2004-07-14]  Birth date[2004-02-19]
and
Visit date[2004-08-11]  Birth date[2003-04-21]

which are clearly people who are < 17.


Any suggestions on how to track down this problem or rework the query so
it always works correctly?  If I reverse the query and look for people <
17, I don't get any that are older than 17.

Thanks,
Bruce


pgsql-general by date:

Previous
From: "Magnus Hagander"
Date:
Subject: Re: subscribe missing?
Next
From: Phil Endecott
Date:
Subject: Re: Temporary tables and disk activity