遇到错误时如何停止Postgres脚本?

编程入门 行业动态 更新时间:2024-10-28 12:23:38
本文介绍了遇到错误时如何停止Postgres脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

有没有一种方法可以指定在执行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

上设置ON_ERROR_STOP

存在更简单方便的方法-将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

p.s。在Peter Eisentraut的重要文章中找到了解决方案。谢谢你,彼得! petereisentraut.blogspot/2010/03/ running-sql-scripts-with-psql.html

p.s. the solution found in great post from Peter Eisentraut. Thank you, Peter! petereisentraut.blogspot/2010/03/running-sql-scripts-with-psql.html

更多推荐

遇到错误时如何停止Postgres脚本?

本文发布于:2023-10-24 07:50:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1523357.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:脚本   错误   Postgres

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!