Unable to Create COMMIT inside PostgreSQL 11.5 Procedure
The

BEGIN;


is wrong and will cause an error. You cannot start a transaction inside a procedure, because there is already an active transaction.

You can end a transaction, which implies that a new transaction is started immediately.

Without the BEGIN;, your procedure works just fine.

The problem must be with the way you are calling it. As the documentation says:


  Transaction control is only possible in CALL or DO invocations from the top level or nested CALL or DO invocations without any other intervening command. For example, if the call stack is CALL proc1() &rarr; CALL proc2() &rarr; CALL proc3(), then the second and third procedures can perform transaction control actions. But if the call stack is CALL proc1() &rarr; SELECT func2() &rarr; CALL proc3(), then the last procedure cannot do transaction control, because of the SELECT in between.


There is probably a SELECT in your call stack.

Another possibility is that you explicitly started a transaction with BEGIN before calling the stored procedure.

This does not work either, which is an undocumented implementation restriction that may be fixed in the future. See this thread for reference.