我正在使用psql命令连接postgreSQL数据库并发出查询.有人能告诉我如何在shell脚本中判断已执行查询的返回状态吗.
我使用了echo $?
命令来判断状态,但它总是返回零.
谢谢你的帮助.
我正在使用psql命令连接postgreSQL数据库并发出查询.有人能告诉我如何在shell脚本中判断已执行查询的返回状态吗.
我使用了echo $?
命令来判断状态,但它总是返回零.
谢谢你的帮助.
psql
返回代码is documented as:
退出状态
你可能只是想用ON_ERROR_STOP.
Failure getting tested and reported to the shell:
$ psql -d test -v "ON_ERROR_STOP=1" <<EOF
select error;
select 'OK';
EOF
ERROR: column "error" does not exist
LINE 1: select error;
$ echo $?
3
Failure getting ignored and not reported to the shell:
$ psql -d test <<EOF
select error;
select 'OK';
EOF
ERROR: column "error" does not exist
LINE 1: select error;
^
?column?
----------
OK
(1 row)
$ echo $?
0