Is there a way to set an option that will cause a PostgreSQL script to continue even if there are errors?

ε祈祈猫儿з 提交于 2019-12-24 05:24:15

问题


Is there a command to set an option that will cause a PostgreSQL script to continue even if there are errors?

eg sometimes when I have a lot of data from a spreadsheet to insert into a table, I use a formula to create INSERT statements, and I copy the statements into a file and execute them, or copy them into a PgAdmin to run them. The accuracy is not always important and I don't want the whole process to fail because of a few records.

Syntax errors are not the issue here, just commands which fail due to some errors, like trying to create an index that already exists, or inserting a duplicate record.


回答1:


If using psql, you want:

\set ON_ERROR_ROLLBACK on

From the manual:

ON_ERROR_ROLLBACK

When on, if a statement in a transaction block generates an error, the error is ignored and the transaction continues. When interactive, such errors are only ignored in interactive sessions, and not when reading script files. When off (the default), a statement in a transaction block that generates an error aborts the entire transaction



来源:https://stackoverflow.com/questions/14908451/is-there-a-way-to-set-an-option-that-will-cause-a-postgresql-script-to-continue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!