Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR SQL

postgres stored procedure

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)
Source by www.postgresqltutorial.com #
 
PREVIOUS NEXT
Tagged: #postgres #stored #procedure
ADD COMMENT
Topic
Name
3+6 =