Thread: Redirecting query's output to a textfile?
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 --
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: > > 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 >
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.
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 ***********************************************************************
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