How can I stop a Postgres script when it encounters an error?

前端 未结 4 774
眼角桃花
眼角桃花 2020-12-13 11:34

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.

4条回答
  •  囚心锁ツ
    2020-12-13 12:19

    I think the solution to add following to .psqlrc is far from perfection

    \set ON_ERROR_STOP on
    

    there exists much more simple and convenient way - use psql with parameter:

    psql -v ON_ERROR_STOP=1
    

    better to use also -X parameter turning off .psqlrc file usage. Works perfectly for me

    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

提交回复
热议问题