You need the whole sequence of DECLARE ... BEGIN ... END in a plpgsql function. Yes, errors are non-obvious with this thing.
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных