By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,660 Members | 1,316 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,660 IT Pros & Developers. It's quick & easy.

piping output to file

P: n/a
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 ]
[ su*******@12jabber.com <--jabber IM ]

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

http://archives.postgresql.org

Nov 22 '05 #1
Share this Question
Share on Google+
3 Replies

P: n/a
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 <kl*****@svana.org> http://svana.org/kleptog/ (... 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


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.0.6 (GNU/Linux)
Comment: For info see http://www.gnupg.org

iD8DBQFAJnj1Y5Twig3Ge+YRAn2CAJ9tNahcRn7ID5gzIiuHxW p2h6BftACfRA2h
FdhRR8LUgY/0xvZL3+RQhRk=
=FF4C
-----END PGP SIGNATURE-----

Nov 22 '05 #2

P: n/a
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:
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 ]
[ su*******@12jabber.com <--jabber IM ]

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

http://archives.postgresql.org

---------------------------(end of broadcast)---------------------------
TIP 4: Don't 'kill -9' the postmaster

Nov 22 '05 #3

P: n/a
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 ma*******@postgresql.org)

Nov 22 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.