Hi,
Ever since I began working with Postgres, I have had one little irritating
problem with psql. It may be that I am mis-using this program; if so, my
suggestion is not helpful, however, if others have encountered this problem,
perhaps the developers can look at a fix for 7.0?
When I develop a new DB schema using psql, I usually first create a file, say
"mySchema.sql". I then "createdb" the database, start up psql, and use the
command "\i mySchema.sql" to load in my new schema. There will be, needless to
say, several errors. These fall nicely below the offending line and I can look
at fixing them. I drop the DB, re-edit my SQL file and re-do the "\i" command.
Sometimes, however, rather than using the "\i" command, I would like to simply
load my schema directly into psql and capture the output on STDOUT (ie "psql <
mySchema.sql >& myOutput"). The problem that arises is that the errors and
notices all come out on STDERR. I am not sure this is the right choice. Because
of the lack of synchronization between STDOUT and STDERR, it becomes impossible
to associate an SQL statement with either a CREATE or an ERROR message. The
option, "-e", is supposed to echo the query, but it doesn't help.
While I can see wanting to separate STDERR and STDOUT when one uses psql to run
an SQL query against a DB from within a shell script, it makes it much more
difficult when developing, and if I were to run several SQL queries into psql,
exactly the same association problem would occur.
Perhaps a combination of the function "isatty()" plus the -e flag would work? So
that if STDOUT "isatty()" then echo errors to STDOUT, otherwise send them to
STDERR. And if the -e flag is set, echo the queries to STDERR, so the
correlation between ERROR, CREATE, etc and SQL could be made.
Just my $0.02.
Mark
PS I only recently learned of the setting of the PAGER environment variable to
make it so I needn't scroll back up 400 lines to find my errors; perhaps this
could be made more prominent in the documentation as it would be a big help.
Then again, perhaps I should completely re-read the docs to see if this is
mentioned; I haven't done that for several releases now.
--
Mark Dalphin email: mdalphin@amgen.com
Mail Stop: 29-2-A phone: +1-805-447-4951 (work)
One Amgen Center Drive +1-805-375-0680 (home)
Thousand Oaks, CA 91320 fax: +1-805-499-9955 (work)