Redirecting query's output to a textfile?

Started by Peter Peltonenabout 24 years ago5 messagesgeneral
Jump to latest
#1Peter Peltonen
peter.peltonen@fivetec.com

A basic question:

How in PostgreSQL do I redirect the output of an SQL query to a textfile?

--
Peter Peltonen
System Administrator
Fivetec Solutions Oy

Melkonkatu 28 E
00210 Helsinki
GSM. +358-40 720 6535
Tel. +358-9-6824 7666
Fax. +358-9-6824 7664
http://www.fivetec.com
mailto:peter.peltonen@fivetec.com
--

#2Thalis A. Kalfigopoulos
thalis@cs.pitt.edu
In reply to: Peter Peltonen (#1)
Re: Redirecting query's output to a textfile?

Depends on how you place the query? I assume you are asking about the psql client, so before the query just do:
\o output.txt

you can see several options/switches by giving \?

regards,
thalis

On Fri, 15 Feb 2002, Peter Peltonen wrote:

Show quoted text

A basic question:

How in PostgreSQL do I redirect the output of an SQL query to a textfile?

--
Peter Peltonen
System Administrator
Fivetec Solutions Oy

Melkonkatu 28 E
00210 Helsinki
GSM. +358-40 720 6535
Tel. +358-9-6824 7666
Fax. +358-9-6824 7664
http://www.fivetec.com
mailto:peter.peltonen@fivetec.com
--

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

#3Bruno Wolff III
bruno@wolff.to
In reply to: Peter Peltonen (#1)
Re: Redirecting query's output to a textfile?

On Fri, Feb 15, 2002 at 06:11:08PM +0200,
Peter Peltonen <peter.peltonen@fivetec.com> wrote:

A basic question:

How in PostgreSQL do I redirect the output of an SQL query to a textfile?

Assuming you are talking about doing this in psql, the answer is to use:
\o filename
\? will provide help on the other psql \ commands.

#4P.J. "Josh" Rovero
rovero@sonalysts.com
In reply to: Thalis A. Kalfigopoulos (#2)
Re: Redirecting query's output to a textfile?

for a single command, \g. Example

select * from employees \g '/home/dbadmin/employees.tab'

Note that there isn't a semicolon at the end. '\g' takes
care of that. '\g' will also let you pipe the table output
to other commands........

Thalis A. Kalfigopoulos wrote:

Depends on how you place the query? I assume you are asking about the psql client, so before the query just do:
\o output.txt

--
P. J. "Josh" Rovero Sonalysts, Inc.
Email: rovero@sonalysts.com www.sonalysts.com 215 Parkway North
Work: (860)326-3671 or 442-4355 Waterford CT 06385
***********************************************************************

#5Herb Blacker
herbblacker@isgenesis.com
In reply to: Peter Peltonen (#1)
Re: Redirecting query's output to a textfile?

If you use psql and your query is in a file, try this:

$psql <dbname>

<dbname># \o <filename> (puts the output of the next query in a file)

<dbname># \i <queryfile> (reads and executes the query from the file)

<dbname> \q (quit psql)

Peter Peltonen wrote:

A basic question:

How in PostgreSQL do I redirect the output of an SQL query to a textfile?

Hope this helps...
_________________________
Herb Blacker
Database Administrator
ReCare, Inc.
(512) 791-4340
herbblacker@isgenesis.com