up vote 4 down vote favorite
share [fb]

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?

link|improve this question

Huh? Report a bug against psql maybe? – alex Jul 17 '11 at 10:09
It can be a reasonably intentional behavior. – Adam Matan Jul 17 '11 at 14:34
feedback

1 Answer

Adding this to the first line of the SQL file does the trick:

\set ON_ERROR_STOP 1
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.