how to detect psql's errors?

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

how to detect psql's errors?

От:
Drew Wilson <amw@speakeasy.net>
Дата:
As part of renaming a database, I'm trying to script some updates to 
system tables, and I can't figure out how to detect an error condition 
in the SQL sent to psql.

Is there anyway to test for errors returned by psql?

For example:
  echo "select foo from pg_database" | psql -U admin myDB || echo 
"failed" && echo "success"

This doesn't work. Neither "failed" nor "success" are echoed.
Only 'ERROR:  Attribute "foo" not found' is displayed on console.


Alternatively, is there a way to do this as a single transaction, that 
will rollback if any statement fails? (Without installing PL/pgSQL, 
that is.)


TIA,

Drew

Re: how to detect psql's errors?

От:
"Peter Gibbs" <peter@emkel.co.za>
Дата:
Drew Wilson wrote:

> Is there anyway to test for errors returned by psql?
>
> For example:
>   echo "select foo from pg_database" | psql -U admin myDB || echo
> "failed" && echo "success"
>
> This doesn't work. Neither "failed" nor "success" are echoed.
> Only 'ERROR:  Attribute "foo" not found' is displayed on console.

Try:
  psql -c "select foo from pg_database" -U admin myDB && echo "success" ||
echo "failed"

--
Peter Gibbs
EmKel Systems

FAQ