Programming with PLpgSQL
Basic PLpgSQL Function
PLpgSQL Syntax
RETURNS Block
custom exceptions