Database Reference
In-Depth Information
Getting ready
Let's start with a trivial script, with a command we know will fail as follows:
$ $EDITOR test.sql
mistake1;
mistake2;
mistake3;
Execute the following script using psql to see what the results look like:
$ psql -f test.sql
psql:test.sql:1: ERROR: syntax error at or near "mistake1"
LINE 1: mistake1;
^
psql:test.sql:2: ERROR: syntax error at or near "mistake2"
LINE 1: mistake2;
^
psql:test.sql:3: ERROR: syntax error at or near "mistake3"
LINE 1: mistake3;
^
How to do it...
To exit the script on first error, we can do the following:
$ psql -f test.sql -v ON_ERROR_STOP=on
psql:test.sql:1: ERROR: syntax error at or near "mistake1"
LINE 1: mistake1;
^
Or, edit the file test.sql with an initial line, like the following:
$ $EDITOR test.sql
\set ON_ERROR_STOP
mistake1;
mistake2;
mistake3;
Note that this will not work because we have missed the crucial ON :
$ psql -f test.sql -v ON_ERROR_STOP
 
Search WWH ::




Custom Search