anonymous blocks inside a transaction I have the following script:

DROP TABLE IF EXISTS a;
CREATE TABLE a(
val   VARCHAR NOT NULL
);


DO
$do$
BEGIN    
    INSERT INTO a(val) VALUES('a1');
    INSERT INTO a(val) VALUES('a2');
END;
$do$


When I place it in file (boo.sql) and execute it with:

psql -v --quiet -X -U some-user --no-password -d some-db -f boo.sql 


... the table gets created and the rows are inserted.
When I try to wrap the anonymous block inside a transaction (so that I can explicitly set and control the transaction isolation level):

DROP TABLE IF EXISTS a;
CREATE TABLE a(
val   VARCHAR NOT NULL
);


BEGIN TRANSACTION;
SET TRANSACTION ISOLATION LEVEL SERIALIZABLE;
DO
$do$
BEGIN    
    INSERT INTO a(val) VALUES('a1');
    INSERT INTO a(val) VALUES('a2');
END;
$do$
COMMIT;


... I get instead:

psql:boo.sql:16: ERROR:  syntax error at or near "COMMIT"
LINE 8:     COMMIT;
            ^


Am I doing something nonsensical? Is there a way to wrap a single or multiple anonymous blocks inside a transaction and if not, then on what transactions do these anonymous blocks get executed and how can I control its transaction isolation level?
There is a semicolon missing after the DO statement:

...
END     -- semicolon is not necessary here
$do$;   -- but here it is
COMMIT;


The first example works, because the semicolon is optional at the end of a script. That's also why the semicolon after END inside the block is optional.