Any ideas what is wrong with this code, Error at or near Insert on a new function
PostgreSQL has several languages for functions, and it is easy to get confused.

PL/pgSQL uses BEGIN / END blocks.

But LANGUAGE sql functions consist only of SQL statements with no blocks ir other procedural elements.

So either change the language to plpgsql and add a semicolon or (better) remove the BEGIN / END block.