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

Re: Sending query to a file

From: "Brett W(dot) McCoy" <bmccoy(at)chapelperilous(dot)net>
To: Francisco Reyes <lists(at)natserv(dot)com>
Cc: Pgsql Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Sending query to a file
Date: 2001-11-10 21:32:16
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-novice
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;

SELECT * FROM sometable WHERE id > 12
\g result.txt

-- Brett
You can always pick up your needle and move to another groove.
		-- Tim Leary

In response to

pgsql-novice by date

Next:From: Mo HolkarDate: 2001-11-11 13:18:14
Subject: Re: SQL Question
Previous:From: Francisco ReyesDate: 2001-11-10 21:15:19
Subject: Re: Sending query to a file

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