使用单个SQL命令运行PostgreSQL时,按预期返回错误代码:
% psql -c "SELECT * FROM AWDASDASDASDAS" my_db
ERROR: relation "awdasdasdasdas" does not exist
LINE 1: SELECT * FROM AWDASDASDASDAS
% echo $?
1
但是在运行文件时,该错误被抑制:
% psql -f test.sql my_db
psql:test.sql:1: ERROR: relation "awdasdasdasdas" does not exist
LINE 1: SELECT * FROM AWDASDASDASDAS
% echo $?
0
任何想法如何找回这些错误?
psql -v ON_ERROR_STOP=on -f file_name.sql