From: | Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Auto Adjust Age |
Date: | 2011-04-06 15:30:43 |
Message-ID: | BANLkTinhN7HgYYsbD3dcSp0Y3LQ-L_x1ww@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Wed, Apr 6, 2011 at 11:20 AM, Andrew Sullivan <ajs(at)crankycanuck(dot)ca> 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;
From | Date | Subject | |
---|---|---|---|
Next Message | Adrian Klaver | 2011-04-06 15:31:11 | Re: Why security-definer functions are executable by public by default? |
Previous Message | Karsten Hilbert | 2011-04-06 15:24:29 | Re: Auto Adjust Age |