Thread: outputting everything from psql to a file
Hello again, I'm stuck on another issue. I need to specify in a sql script I'm calling from psql that I want everything to go to an output file. So, I have in my sql file: \o example1.lst \qecho This is an example select current_user; select hope from none; The problem I have is that the output of the first query and the error from the second query go to standard out/error (it appears) and not to the output file. I need everything to go to the output file. I can't find anything in the psql documentation on how to do this. Is there a way? Or do I have to do something like: { psql -U user <<EOF \echo This is an example select current_user; select hope from none; EOF } > example1.lst 2>&1 which gives me what I want except that the error goes to both the output file and the screen. Thanks again, Jed S. Walker
"Walker, Jed S" <Jed_Walker@cable.comcast.com> writes: > I'm stuck on another issue. I need to specify in a sql script I'm calling > from psql that I want everything to go to an output file. So, I have in my > sql file: > \o example1.lst > \qecho This is an example > select current_user; > select hope from none; > The problem I have is that the output of the first query and the error from > the second query go to standard out/error (it appears) and not to the output > file. I need everything to go to the output file. I don't think that there is any way to get error messages to go to a \o file, but both \qecho output and query output do go there in a simple test. > ...which gives me what I want except that the error goes to both the output > file and the screen. Hm? It can't go to the screen when you've redirected stderr like that. Perhaps you are testing this on the same console where you started the postmaster, and you didn't redirect the postmaster log somewhere? If so you're getting confused by the postmaster's log output. regards, tom lane
that was it Tom. I closed my terminal, opened a new terminal, ran it again and it didn't show on stdout. Thanks! I am still wondering if there's a way to do this but purely from within psql? -----Original Message----- From: Tom Lane [mailto:tgl@sss.pgh.pa.us] Sent: Friday, March 25, 2005 12:45 PM To: Walker, Jed S Cc: 'pgsql-novice@postgresql.org' Subject: Re: [NOVICE] outputting everything from psql to a file "Walker, Jed S" <Jed_Walker@cable.comcast.com> writes: > I'm stuck on another issue. I need to specify in a sql script I'm calling > from psql that I want everything to go to an output file. So, I have in my > sql file: > \o example1.lst > \qecho This is an example > select current_user; > select hope from none; > The problem I have is that the output of the first query and the error from > the second query go to standard out/error (it appears) and not to the output > file. I need everything to go to the output file. I don't think that there is any way to get error messages to go to a \o file, but both \qecho output and query output do go there in a simple test. > ...which gives me what I want except that the error goes to both the output > file and the screen. Hm? It can't go to the screen when you've redirected stderr like that. Perhaps you are testing this on the same console where you started the postmaster, and you didn't redirect the postmaster log somewhere? If so you're getting confused by the postmaster's log output. regards, tom lane
On Mar 25, 2005, at 2:50 PM, Walker, Jed S wrote: > I am still wondering if there's a way to do this but purely from within > psql? I don't think so. I asked a similar question recently and did not get any responses. http://archives.postgresql.org/pgsql-general/2005-02/msg00134.php John DeSoi, Ph.D. http://pgedit.com/ Power Tools for PostgreSQL