This is unsuitable:
LANGUAGE sql
use this instead:
LANGUAGE plpgsql
The syntax you are trying to use is not pure SQL, but the procedural language PL / pgSQL. In PostgreSQL you can install different languages, and PL / pgSQL is only primus inter pares for that matter. It also means that you may receive an error message that this language is not installed. In this case, use
CREATE LANGUAGE plpgsql;
which acts on him. Depending on the version of PostgreSQL, you may need superuser privileges to take this step.
Good luck.
source share