Re: how to detect errors in statements piped to psql? - Mailing list pgsql-general

From Martijn van Oosterhout
Subject Re: how to detect errors in statements piped to psql?
Date
Msg-id 20030225074834.GA28004@svana.org
Whole thread Raw
In response to how to detect errors in statements piped to psql?  (Drew Wilson <amw@speakeasy.net>)
List pgsql-general
If you do them all in one session and surround them with BEGIN and COMMIT
then it'll become an all or nothing affair.

On Mon, Feb 24, 2003 at 06:29:27PM -0800, Drew Wilson wrote:
> 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
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://archives.postgresql.org

--
Martijn van Oosterhout   <kleptog@svana.org>   http://svana.org/kleptog/
> Support bacteria! They're the only culture some people have.

Attachment

pgsql-general by date:

Previous
From: Drew Wilson
Date:
Subject: how to detect psql's errors?
Next
From: Antti Haapala
Date:
Subject: Re: How do I change the server encoding?