Error on defining postgres age calculated column

Solution 1:

You can use this. it will solve it.

CREATE OR REPLACE FUNCTION calculate_age( birthday timestamp )
RETURNS integer
AS $CODE$
BEGIN
    RETURN date_part('year',age(birthday));
END
$CODE$
LANGUAGE plpgsql IMMUTABLE;


CREATE TABLE Customer (
    birth_date timestamp not null,
    age text GENERATED ALWAYS AS (calculate_age(birth_date)) stored
);