Re: Does psql -f quit insertion after an error in a statement has been detected?

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: "Wang, Mary Y" <mary(dot)y(dot)wang(at)boeing(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Does psql -f quit insertion after an error in a statement has been detected?
Date: 2010-07-03 16:30:53
Message-ID: 201007031630.o63GUrR06964@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wang, Mary Y wrote:
> Hi,
>
> I'm using a psql -f command to reload the data from a dump file. I
> noticed that some tables are not populated with any rows (I mean 0
> rows), yet, if I manually insert a row (actually just copy an INSERT
> statement from that input file) in the interactive terminal, that row
> was added with no problem. So my question "does psql -f quits inserting
> rows for a table when it detects there is an error in a statement?".
> The impression that I got is that even though other rows might not have
> any errors, but psql -f seems just quits after it detects an error in
> a row.

Unless you set ON_ERROR_STOP in psql, psql will continue reading the
file and executing commands:

<term><varname>ON_ERROR_STOP</varname></term>
<listitem>
<para>
By default, if non-interactive scripts encounter an error, such
as a malformed <acronym>SQL</acronym> command or internal
meta-command, processing continues. This has been the
traditional behavior of <application>psql</application> but it
is sometimes not desirable. If this variable is set, script
processing will immediately terminate. If the script was called
from another script it will terminate in the same fashion. If
the outermost script was not called from an interactive
<application>psql</application> session but rather using the
<option>-f</option> option, <application>psql</application> will
return error code 3, to distinguish this case from fatal error
conditions (error code 1).

--
Bruce Momjian <bruce(at)momjian(dot)us> http://momjian.us
EnterpriseDB http://enterprisedb.com

+ None of us is going to be here forever. +

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Bruce Momjian 2010-07-03 17:27:16 Re: Requested addition to the todo list [was]: Re: Altering Domain Constraints on composite types
Previous Message aaaawwww 2010-07-03 13:45:52 Re: problems with encoding and accent letters