Обсуждение: Sending query to a file
What is the best way to send a query to an ASCII file? I have been using "\g", but that seems to require doing the query twice. I do a query and when done I then do '\g <filename>'. It works, but for a lengthy query it can take very long having to do the query twice.
On Sat, 10 Nov 2001, Francisco Reyes wrote:
> What is the best way to send a query to an ASCII file?
> I have been using "\g", but that seems to require doing the query twice. I
> do a query and when done I then do '\g <filename>'. It works, but for a
> lengthy query it can take very long having to do the query twice.
\o <file> will send the results of queries to a file.
-- Brett
http://www.chapelperilous.net/
------------------------------------------------------------------------
Courage is your greatest present need.
On Sat, 10 Nov 2001, Brett W. McCoy wrote: > On Sat, 10 Nov 2001, Francisco Reyes wrote: > > What is the best way to send a query to an ASCII file? > > I have been using "\g", but that seems to require doing the query twice. I > \o <file> will send the results of queries to a file. Thanks. That worked. Is there a better way to use "\g" than running it after running the query initially? The description says "send query to backend (and results in [file] or |pipe)". For starters when I do "\g" it doesn't seem to go to the backend. It processes the last query and I don't get the prompt back until it is done.
On Sat, 10 Nov 2001, Francisco Reyes wrote:
> Thanks. That worked.
> Is there a better way to use "\g" than running it after running the query
> initially?
> The description says "send query to backend (and results in [file] or
> |pipe)". For starters when I do "\g" it doesn't seem to go to the backend.
> It processes the last query and I don't get the prompt back until it is
> done.
Why do you need to use \g? Just terminate your query with a semi-colon
and press enter. They do the same thing. If you want to save the result
of a query, start your session with \o [file], and use \o without any
options to make query results go back to stdout. Or use \g [file] in one
shot. These are more or less the same:
\o result.txt
SELECT * FROM sometable WHERE id > 12;
\o
SELECT * FROM sometable WHERE id > 12
\g result.txt
-- Brett
http://www.chapelperilous.net/
------------------------------------------------------------------------
You can always pick up your needle and move to another groove.
-- Tim Leary