CREATE OR REPLACE FUNCTION public.date_submission(state varchar, created_at date, updated_at date)
returns date
LANGUAGE plpgsql
IMMUTABLE
AS $function$
declare
response date;
begin
if (state = 'CREATED' or state = 'PENDING' or state = 'PENDING - RESUBMITTED') then
response = updated_at;
else
response = created_at;
end if;
return response;
end;
$function$
select date_submission('PENDING', now()::date, now()::date)