How to execute two transactions concurrently in PostgreSQL?
Each pgAdmin query window has it's own session. You can run one transaction at a time in each session. It's not possible to run two transactions concurrently in the same session (at least not in pgAdmin or psql).

You can open and bind more sessions to the same query window with the "connection bar" in the menu of the query window, then switch between multiple open sessions. But it's simpler to just open another query window.

pgAdmin runs everything you execute at once inside a transaction. It's wrapped into BEGIN; .. COMMIT; implicitly - unless you issue explicit transaction control commands.

Start a transaction start with BEGIN; followed by SQL commands and don't commit yet. Switch to the other query window and do the same. Now both transactions are running concurrently. Some effects don't show until you COMMIT; one or both transactions.

Similar answer with detailed instructions on SO:


How to simulate deadlock in PostgreSQL?


As for your code and error message:

Like @Jack already told you, you are using PL/pgSQL code, the default procedural language extension in Postgres (similar to PL/SQL in Oracle). It's only valid in a function or anonymous code block.

A code block can only be executed as a whole.