Re: how to detect errors in statements piped to psql?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: Drew Wilson <amw(at)speakeasy(dot)net>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: how to detect errors in statements piped to psql?
Date: 2003-02-25 07:48:35
Message-ID: 20030225074834.GA28004@svana.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)svana(dot)org> http://svana.org/kleptog/
> Support bacteria! They're the only culture some people have.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Antti Haapala 2003-02-25 07:55:09 Re: How do I change the server encoding?
Previous Message Carlos Moreno 2003-02-25 05:44:25 Re: Strange error (Socket command option unknown)