Search Postgresql Archives

Re: Auto Adjust Age

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Wed, Apr 6, 2011 at 11:20 AM, Andrew Sullivan <ajs@xxxxxxxxxxxxxxx> wrote:
> Why do you have the age stored at all?  When you SELECT from the table
> and want someone's age, just do
>
>    SELECT [. . .], extract('years' from age(CURRENT_TIMESTAMP,dob)) as age
>           . . . FROM users . . .
>
> By and large, it's not a good idea to store something you can
> calculate from other data you have.

I'm very sorry as I didn't know PG or SQL could auto calculate age
with existing parameters. I'm trying to learn as much SQL as I can
during my spare time. I tried the following and it worked great!

ide=# SELECT extract('years' from age(CURRENT_TIMESTAMP,dob)) as age
FROM users;
 age
-----
  31
(1 row)


THANK YOU;

-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux