PostgreSQL exit status when running a file
Adding this to the first line of the SQL file does the trick:

\set ON_ERROR_STOP 1


New comments (Thanks!) suggest the following solutions:

-v ON_ERROR_STOP=1
-v ON_ERROR_STOP=on