I get the following error, can someone give me an example to avoid it:
ERROR:  cannot begin/end transactions in PL/pgSQL
HINT:  Use a BEGIN block with an EXCEPTION clause instead.
CONTEXT:  PL/pgSQL function transfer(integer,integer,numeric) line 13 at SQL statement
PL/pgSQL function inline_code_block line 2 at EXECUTE
SQL state: 0A000
START TRANSACTION;
    DO
    $$BEGIN
     EXECUTE transfer(1,2,1000);
    END$$;
COMMIT TRANSACTION;
 
                        
In PostgreSQL version 10, it is not possible to run transaction control commands (COMMIT, ROLLBACK) inside a stored function.
Either take the transaction control statement out of the stored function (line 13 of the
transfer()function) or upgrade to a newer PostgreSQL release and turn the function into a stored procedure.