From: | Jasen Betts <jasen(at)xnet(dot)co(dot)nz> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Auto Adjust Age |
Date: | 2011-04-20 13:00:03 |
Message-ID: | iomlcj$tn0$1@reversiblemaps.ath.cx |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On 2011-04-06, Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com> wrote:
> I've only been using PostgreSQL since Oct 2010 and it's my first
> experience with SQL or any ORDBMS. I've searched on the web and been
> creating my own database users, databases, tables from scratch which
> has been interesting to say the least but now I would like to know if
> this is possible in SQL or PostgreSQL since I can't find anything
> online that shows me how to do so. I've created a table called 'users'
> and I have it configured as follows:
>
> CREATE TABLE users
> (
> id integer PRIMARY KEY UNIQUE NOT NULL, --ID
> fname character varying(40) NOT NULL, --First name
> lname character varying(40) NOT NULL, --Last name
> email character varying NOT NULL, --email address
> office integer NOT NULL, --Office number
> dob date NOT NULL, --Date of birth
> age integer NOT NULL --Age
> )
> ;
>
> Is there a way in SQL I can have the users 'age' be auto adjusted
> based on the 'id' & 'dob'?
I'm not sure how id can be used here.
Running this each morning will keep it current. for the normal
definition of human age.
update user set age=extract('year' from age(dob))
where age is distinct from extract('year' from age(dob));
a cleaner way is to create a view and present a computed age
column in the view
--
⚂⚃ 100% natural
From | Date | Subject | |
---|---|---|---|
Next Message | Jasen Betts | 2011-04-20 13:07:27 | Re: Auto Adjust Age |
Previous Message | Phoenix Kiula | 2011-04-20 10:56:01 | Re: Help - corruption issue? |