470,614 Members | 1,445 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,614 developers. It's quick & easy.

piping output to file

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
3 21220
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
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
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.

Similar topics

2 posts views Thread by Bob | last post: by
reply views Thread by jebbyleezer | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.