select row_to_json(a) from ( select COALESCE(( select array_to_json(array_agg(row_to_json(d))) from ( select column, co