postgres function definition code example

Example 1: create function in postgresql

create [or replace] function function_name(param_list)
   returns return_type 
   language plpgsql
as $$
declare 
-- variable declaration
begin
 -- logic
end;
$$

Example 2: plpgsql create function

CREATE FUNCTION function_name(argument1 type,argument2 type)
 RETURNS type AS
BEGIN
  staments;
END;
LANGUAGE 'language_name';

Example 3: postgresql functions

CASE
     WHEN condition_1  THEN result_1
     WHEN condition_2  THEN result_2
     ...
     ELSE  result_n
END

Tags:

Sql Example