From: magodo <wztdyl@sina.com>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Postgres general <pgsql-general@postgresql.org>
Subject: Re: psql dones't reflect exit status if input command via stdin
Date: Tue, 14 May 2019 15:24:21 +0800
Message-ID: <30cea72b59177bb5a611d540e9fe40d48ba8243b.camel@sina.com> (raw)
In-Reply-To: <CAKFQuwZo3-nx6E88i-3UbuJ20f=Oy+uBWHxK9LRt7cVkNDCx2g@mail.gmail.com>
References: <ee57f43d501e57e7dfa70be17b6345ae2e9ffdcb.camel@sina.com>
<CAKFQuwZo3-nx6E88i-3UbuJ20f=Oy+uBWHxK9LRt7cVkNDCx2g@mail.gmail.com>
On Mon, 2019-05-13 at 23:39 -0700, David G. Johnston wrote:
> On Mon, May 13, 2019 at 11:24 PM magodo <wztdyl@sina.com> wrote:
> > I found when running command like `# echo "xxx" | psql postgres
> >
> > postgres`, the return code is always 0 even though the command
> > ("xxx")
> >
> > here is of invalid syntax. While the `psql -c` way handled exit
> > code
> >
> > correctly.
>
> Its only required to handle things as documented, which this is:
>
> "psql returns 0 to the shell if it finished normally, 1 if a fatal
> error of its own occurs (e.g. out of memory, file not found), 2 if
> the connection to the server went bad and the session was not
> interactive, and 3 if an error occurred in a script and the variable
> ON_ERROR_STOP was set."
>
> The pipe-version causes psql to execute stdin as a script. By
> default ON_ERROR_STOP is unset. Thus psql finished processing the
> script normally and while it encountered an error it continued past
> the error as opposed to stopping with exit code 3.
>
> Adding "\set ON_ERROR_STOP 1" to your .psqlrc will result in psql
> behaving in the way you expect.
>
> David J.
Hi David,
Thank you for your quick and excellent answer 😊
---
Zhaoting.Weng
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: wztdyl@sina.com, david.g.johnston@gmail.com
Subject: Re: psql dones't reflect exit status if input command via stdin
In-Reply-To: <30cea72b59177bb5a611d540e9fe40d48ba8243b.camel@sina.com>
References: <ee57f43d501e57e7dfa70be17b6345ae2e9ffdcb.camel@sina.com> <CAKFQuwZo3-nx6E88i-3UbuJ20f=Oy+uBWHxK9LRt7cVkNDCx2g@mail.gmail.com> <30cea72b59177bb5a611d540e9fe40d48ba8243b.camel@sina.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox