Re: Auto Adjust Age - Mailing list pgsql-general

From Jasen Betts
Subject Re: Auto Adjust Age
Date
Msg-id iomlcj$tn0$1@reversiblemaps.ath.cx
Whole thread Raw
In response to Auto Adjust Age  (Carlos Mennens <carlos.mennens@gmail.com>)
List pgsql-general
On 2011-04-06, Carlos Mennens <carlos.mennens@gmail.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

pgsql-general by date:

Previous
From: Phoenix Kiula
Date:
Subject: Re: Help - corruption issue?
Next
From: Jasen Betts
Date:
Subject: Re: Auto Adjust Age