PostgreSQL exit status when running a file When running PostgreSQL with a single SQL command error codes are returned as expected:

% psql -c "SELECT * FROM AWDASDASDASDAS" my_db
ERROR:  relation "awdasdasdasdas" does not exist
LINE 1: SELECT * FROM AWDASDASDASDAS
% echo $?
1


But when running a file, the error is suppressed:

% psql -f test.sql my_db
psql:test.sql:1: ERROR:  relation "awdasdasdasdas" does not exist
LINE 1: SELECT * FROM AWDASDASDASDAS
% echo $?
0


Any idea how to get these errors back?
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