Re: Auto Adjust Age

From: Jerry Sievers <gsievers19(at)comcast(dot)net>
To: Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Auto Adjust Age
Date: 2011-04-06 15:15:31
Message-ID: 878vvnl8bw.fsf@comcast.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Carlos Mennens <carlos(dot)mennens(at)gmail(dot)com> writes:

> 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 would assume this is possible because if
> you have 100 employees, I doubt someone has time to sit and change
> everyone's age from 31 > 32 on their birthday. Can someone please help
> explain how this works or what the SQL code would look like assuming
> that it's possible? I have no advanced far enough to see what triggers
> and views are so perhaps it's just my level with SQL in general.

I'd suggest not storing age but instead wrapping with a view that calls
date_trunc('year', now() - dob).

If you must store the age then you have to run a daily batch to make the
bulk update.

HTH

--
Jerry Sievers
e: gsievers19(at)comcast(dot)net
p: 305.321.1144

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rob Sargent 2011-04-06 15:18:06 Re: Auto Adjust Age
Previous Message Merlin Moncure 2011-04-06 15:11:39 Re: Functions as first-class values