1create [or replace] function function_name(param_list)
2 returns return_type
3 language plpgsql
4as $$
5declare
6-- variable declaration
7begin
8 -- logic
9end;
10$$
1CASE
2 WHEN condition_1 THEN result_1
3 WHEN condition_2 THEN result_2
4 ...
5 ELSE result_n
6END
7