Обсуждение: psql exit code

Поиск
Список
Период
Сортировка

psql exit code

От
Ivan Sergio Borgonovo
Дата:
I'm running:

ON_ERROR_STOP="on" PGPASSFILE="/somewhere" psql dbname username -f
script.sql
(or alternatively <script.sql)

echo $?
always returns 0 even when sql is clearly wrong.

If I do:
ON_ERROR_STOP="on" PGPASSFILE="/somewhere" psql dbname username -c
"selectz 1 from pippo;"

echo $?
returns 1

psql (PostgreSQL) 8.3.4

How can I know if something went wrong other than parsing the output?

Thanks

--
Ivan Sergio Borgonovo
http://www.webthatworks.it


Re: psql exit code

От
Richard Huxton
Дата:
Ivan Sergio Borgonovo wrote:
> I'm running:
>
> ON_ERROR_STOP="on" PGPASSFILE="/somewhere" psql dbname username -f
> script.sql
> (or alternatively <script.sql)
>
> echo $?
> always returns 0 even when sql is clearly wrong.

I don't think ON_ERROR_STOP is read from the environment, you need to
define it as a psql variable.

psql -v 'ON_ERROR_STOP=on' ...

That should give you an error code.

--
  Richard Huxton
  Archonet Ltd

Re: psql exit code

От
Ivan Sergio Borgonovo
Дата:
On Mon, 10 Nov 2008 10:56:57 +0000
Richard Huxton <dev@archonet.com> wrote:

> Ivan Sergio Borgonovo wrote:
> > I'm running:
> >
> > ON_ERROR_STOP="on" PGPASSFILE="/somewhere" psql dbname username
> > -f script.sql
> > (or alternatively <script.sql)
> >
> > echo $?
> > always returns 0 even when sql is clearly wrong.
>
> I don't think ON_ERROR_STOP is read from the environment, you need
> to define it as a psql variable.
>
> psql -v 'ON_ERROR_STOP=on' ...
>
> That should give you an error code.

Thanks. You're right.

--
Ivan Sergio Borgonovo
http://www.webthatworks.it