Postgres: Non zero exit code when executing a sql file?
You can use below statement.
psql -v ON_ERROR_STOP=1 -f foobar.sql
This will return the correct return code even foobar.sql
file doesn't enable ON_ERROR_STOP
at the top of the file.
I found out how to resolve this.
I need to enable ON_ERROR_STOP
at the top of the file.
Example:
\set ON_ERROR_STOP true