Use PL/pgSQL in PostgreSQL outside of a stored procedure or function?
There is the DO command for ad-hoc plpgsql execution.
But you cannot pass parameters or return rows directly to / from a DO command.
BTW, strictly speaking, Postgres does not have &quot;stored procedures&quot; before Postgres 11. Just functions providing very similar functionality. See:

In PostgreSQL, what is the difference between a &quot;Stored Procedure&quot; and other types of functions?