遇到错误时如何停止 Postgres 脚本? [英] How can I stop a Postgres script when it encounters an error?
问题描述
有没有办法指定在执行 sql 脚本时遇到脚本上的第一个错误时停止,通常会继续执行,而不管之前的错误如何.
Is there a way to specify that when executing a sql script it stops when encountering the first error on the script, it usually continues, regardless of previous errors.
推荐答案
我认为将以下内容添加到 .psqlrc 的解决方案远非完美
I think the solution to add following to .psqlrc is far from perfection
set ON_ERROR_STOP on
存在更简单方便的方法 - 使用带参数的 psql:
there exists much more simple and convenient way - use psql with parameter:
psql -v ON_ERROR_STOP=1
最好同时使用 -X
参数来关闭 .psqlrc 文件的使用.非常适合我
better to use also -X
parameter turning off .psqlrc file usage.
Works perfectly for me
附言在 Peter Eisentraut 的精彩帖子中找到的解决方案.谢谢你,彼得!http://petereisentraut.blogspot.com/2010/03/running-sql-scripts-with-psql.html
p.s. the solution found in great post from Peter Eisentraut. Thank you, Peter! http://petereisentraut.blogspot.com/2010/03/running-sql-scripts-with-psql.html
这篇关于遇到错误时如何停止 Postgres 脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!