piping output to file

Started by Russ Schneiderabout 22 years ago5 messagesgeneral
Jump to latest
#1Russ Schneider
russ@sugapablo.com

Is there an easy way to pipe a select statement's output to a file?

--
[ Russ Schneider (a.k.a. Sugapablo) ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ sugapablo@12jabber.com <--jabber IM ]

#2Martijn van Oosterhout
kleptog@svana.org
In reply to: Russ Schneider (#1)
Re: piping output to file

On Sun, Feb 08, 2004 at 12:28:21PM -0500, Russ Schneider wrote:

Is there an easy way to pipe a select statement's output to a file?

In psql, type \? and look at what \o and \g do. They both do it but slightly
differently.

--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

(... have gone from d-i being barely usable even by its developers
anywhere, to being about 20% done. Sweet. And the last 80% usually takes
20% of the time, too, right?) -- Anthony Towns, debian-devel-announce

#3Adam Ruth
aruth@intercation.com
In reply to: Russ Schneider (#1)
Re: piping output to file

That would depend on the client you're using. psql can do it either
directly (using \o) or by piping its output: psql -c "select * from
mytable;" mydb > out.txt

If you're using a programming library, I think you're on your own.

Adam Ruth

On Feb 8, 2004, at 10:28 AM, Russ Schneider wrote:

Show quoted text

Is there an easy way to pipe a select statement's output to a file?

--
[ Russ Schneider (a.k.a. Sugapablo) ]
[ http://www.sugapablo.com <--music ]
[ http://www.sugapablo.net <--personal ]
[ sugapablo@12jabber.com <--jabber IM ]

---------------------------(end of
broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

#4scott.marlowe
scott.marlowe@ihs.com
In reply to: Russ Schneider (#1)
Re: piping output to file

On Sun, 8 Feb 2004, Russ Schneider wrote:

Is there an easy way to pipe a select statement's output to a file?

In psql you can use \o [filename] to direct query output to a file.

#5Reid Thompson
Reid.Thompson@ateb.com
In reply to: scott.marlowe (#4)
Re: piping output to file

also,

$ psql -c "select whatever_you_want from table_name" > outfile

reid

Show quoted text

-----Original Message-----
From: scott.marlowe [mailto:scott.marlowe@ihs.com]
Sent: Monday, February 09, 2004 12:17 PM
To: Russ Schneider
Cc: pgsql-general
Subject: Re: [GENERAL] piping output to file

On Sun, 8 Feb 2004, Russ Schneider wrote:

Is there an easy way to pipe a select statement's output to a file?

In psql you can use \o [filename] to direct query output to a file.

---------------------------(end of
broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to
majordomo@postgresql.org)