Can COALESCE be used with PERFORM/EXECUTE in PostgreSQL?
EXECUTE is a PL/pgSQL statement, not an SQL statement, so you cannot use it as subquery inside an SQL statement.
You could write a function status_calc_by_time, then your code would work if you simply remove the EXECUTE.
If you write the function in LANGUAGE sql and make it VOLATILE, it might get inlined by the database, so you have no performance loss at all.