eat*_*hil 1 linux postgresql bash psql
如果找到零行,我希望我的 psql 命令失败:
psql -U postgres -d db -c "select * from user where id=1 and name='Joe';"
Run Code Online (Sandbox Code Playgroud)
我希望能够检查返回值。如果至少存在一行,则从进程(!)返回 0,如果不存在这样的行,则从 psql 进程返回非零值。如果找不到行,如何设置返回码?
我不认为 psql 可以自己完成,但是如果您只想查看退出状态是否有任何行,您可以将它组合起来
psql -U postgres -d db -t -c "select * from user where id=1 and name='Joe'" | egrep .
Run Code Online (Sandbox Code Playgroud)
如果 egrep 无法匹配任何内容,这将导致 egrep 以非零值退出。这-t
将使它不打印列标题和摘要信息,因此如果您需要这些内容,您可能需要调整此命令行。
归档时间: |
|
查看次数: |
2225 次 |
最近记录: |