psql exit code, bug ?

Started by Grzegorz Jaśkiewiczover 16 years ago3 messagesgeneral
Jump to latest
#1Grzegorz Jaśkiewicz
gryzman@gmail.com

http://gj.pastebin.com/f119e67bc

Looks like psql loves to report on errors, only when -c is used,
otherwise return code is always 0...

I tested 8.3 and cvs-head, both have the same issue.

Is that the 'by design' (bug/feature) ?

--
GJ

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Grzegorz Jaśkiewicz (#1)
Re: psql exit code, bug ?

=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= <gryzman@gmail.com> writes:

Looks like psql loves to report on errors, only when -c is used,
otherwise return code is always 0...

The documentation seems perfectly clear on this point:

psql returns 0 to the shell if it finished normally, 1 if a fatal error of its own (out of memory, file not found) occurs, 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.

regards, tom lane

#3Grzegorz Jaśkiewicz
gryzman@gmail.com
In reply to: Tom Lane (#2)
Re: psql exit code, bug ?

2009/9/16 Tom Lane <tgl@sss.pgh.pa.us>:

=?UTF-8?Q?Grzegorz_Ja=C5=9Bkiewicz?= <gryzman@gmail.com> writes:

Looks like psql loves to report on errors, only when -c is used,
otherwise return code is always 0...

The documentation seems perfectly clear on this point:

psql returns 0 to the shell if it finished normally, 1 if a fatal error of its own (out of memory, file not found) occurs, 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.

Well, but what you are looking for from - say - script, that calls
psql to perform single action - is a meaningful exit code. That would
specify whether SQL code returned any errors or not.
This clearly shows, that you can rely only on -c, but others - appear
to be inconsistent. (behave different, depending on how you feed the
input to psql).

--
GJ