1

I have a fruit orchard dataset. One of the columns contain the year the orchard was planted. In another column I would like to have the orchard age. However this pose a problem, since the age changes every year.

My question: Is it possible to auto calculate orchard age based on the year column in postgis? If it is possible, please specify how.

PyMapr
  • 1,630
  • 1
  • 16
  • 31

1 Answers1

6

Make a view in PostgreSQL, where the age column can be dynamically created using some useful functions:

SELECT date_trunc('month', age(now()::date, '1994-03-19'::date)) AS age;
       age
-----------------
 19 years 5 mons
(1 row)
Mike T
  • 42,095
  • 10
  • 126
  • 187