Re: psql dones't reflect exit status if input command via stdin

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: psql dones't reflect exit status if input command via stdin
Дата
Msg-id CAKFQuwZo3-nx6E88i-3UbuJ20f=Oy+uBWHxK9LRt7cVkNDCx2g@mail.gmail.com
обсуждение исходный текст
Ответ на psql dones't reflect exit status if input command via stdin  (magodo <wztdyl@sina.com>)
Ответы Re: psql dones't reflect exit status if input command via stdin  (magodo <wztdyl@sina.com>)
Список pgsql-general
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.

В списке pgsql-general по дате отправления:

Предыдущее
От: magodo
Дата:
Сообщение: psql dones't reflect exit status if input command via stdin
Следующее
От: magodo
Дата:
Сообщение: Re: psql dones't reflect exit status if input command via stdin