SQL functions
Examples
For each book, find age of author on publication date
jao=# select name, title, (to_date(year::varchar, 'YYYY') - birth_date) / 365
jao-# from author join book using(author_id);
name | title | ?column?
--------------------+-------------------------+----------
Kurt Vonnegut Jr. | Cat's Cradle | 40
Kurt Vonnegut Jr. | Slaughterhouse Five | 46
Kurt Vonnegut Jr. | Mother Night | 39
John Kennedy Toole | A Confederacy of Dunces | 42
Margaret Atwood | The Handmaid's Tale | 46
Margaret Atwood | The Testaments | 80
Hannah Orenstein | Playing With Matches | 25
Hannah Orenstein | Love at First Like | 26
Hannah Orenstein | Head Over Heels | 27
(9 rows)
|