create or replace function trunc (x timestamp)
returns date
language plpgsql as $function$
begin
return date_trunc('year', to_date((to_char(coalesce($1, current_timestamp), 'YYYY-MM-DD')), 'YYYY-MM-DD'));
end
$function$;
select trunc(now()::timestamp);
select trunc(null::timestamp);