how to detect errors in statements piped to psql?

From: Drew Wilson <amw(at)speakeasy(dot)net>
To: pgsql-general(at)postgresql(dot)org
Subject: how to detect errors in statements piped to psql?
Date: 2003-02-25 02:29:27
Message-ID: F63008AC-4868-11D7-BE13-00039342B2CE@speakeasy.net
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-02-25 03:52:53 Re: Strange error (Socket command option unknown)
Previous Message Doug McNaught 2003-02-25 02:08:11 Re: Strange error (Socket command option unknown)