I'm trying to use custom cast for to_json() function for timestamp type. We are using 3rd party tool which dynamically generates all SQLs so can't directly use to_char() in the SQL to format the timestamp.
-- here is the user defined function to do the conversion from timestamp to json
CREATE or replace FUNCTION mytimecast(val timestamp with time zone) RETURNS json AS $$