Re: SELECTing on age

From: "Kall, Bruce A(dot)" <kall(at)mayo(dot)edu>
To: pgsql-general(at)postgresql(dot)org
Cc: "Kall, Bruce A(dot)" <kall(at)mayo(dot)edu>
Subject: Re: SELECTing on age
Date: 2004-12-13 21:15:46
Message-ID: 41BE0682.9070001@mayo.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Phil Endecott 2004-12-13 21:18:09 Re: Temporary tables and disk activity
Previous Message Magnus Hagander 2004-12-13 20:59:08 Re: subscribe missing?