Wie man dynamisch das Alter anhand eines Geburtsdatums mit PostgreSQL bestimmt? Ganz einfach:
SELECT
id,
firstname,
lastname,
date_of_birth,
EXTRACT(YEAR FROM age(users.date_of_birth::DATE)) AS age
FROM users;
/*
id |firstname |lastname |date_of_birth |age
-----------------------------------------------------
24 |"Max" |"Mustermann" |"1987-08-12" |25
51 |"John" |"Doe" |"1985-02-03" |28
*/
id,
firstname,
lastname,
date_of_birth,
EXTRACT(YEAR FROM age(users.date_of_birth::DATE)) AS age
FROM users;
/*
id |firstname |lastname |date_of_birth |age
-----------------------------------------------------
24 |"Max" |"Mustermann" |"1987-08-12" |25
51 |"John" |"Doe" |"1985-02-03" |28
*/