Re: Auto Adjust Age

Поиск
Список
Период
Сортировка
От Jasen Betts
Тема Re: Auto Adjust Age
Дата
Msg-id iomlcj$tn0$1@reversiblemaps.ath.cx
обсуждение исходный текст
Ответ на Auto Adjust Age  (Carlos Mennens <carlos.mennens@gmail.com>)
Список 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 по дате отправления:

Предыдущее
От: Phoenix Kiula
Дата:
Сообщение: Re: Help - corruption issue?
Следующее
От: Jasen Betts
Дата:
Сообщение: Re: Auto Adjust Age