Skip site navigation (1) Skip section navigation (2)

how to detect psql's errors?

From: Drew Wilson <amw(at)speakeasy(dot)net>
To: Postgresql General <pgsql-general(at)postgresql(dot)org>
Subject: how to detect psql's errors?
Date: 2003-02-25 05:39:55
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
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.)




pgsql-general by date

Next:From: Carlos MorenoDate: 2003-02-25 05:44:25
Subject: Re: Strange error (Socket command option unknown)
Previous:From: Carlos MorenoDate: 2003-02-25 05:38:24
Subject: Re: Strange error (Socket command option unknown)

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group