DROP DATABASE
is a very special command that cannot be undone. To my knowledge there is no way to drop a database inside a transaction. I quote the manual:
DROP DATABASE cannot be executed inside a transaction block.
Whenever you run two commands in a script, they are automatically wrapped into a transaction. You can explicitly begin and commit transactions, but you cannot run multiple commands in one session "outside" of a transaction.
Therefore, you can only run this as a separate command. You could use the program dropdb
from the shell - or write a shell-script with it that drops multiple database in succession.
BTW, the only difference between what you can run from pgAdmin and from psql
are the meta-comnmands of psql - which are not SQL. Those are interpreted by psql and not sent to the database engine. You cannot mix meta-commands and SQL.