Discussion:
How do I pipe output from query to a file in PostgreSQL?
Penrod, John
2009-10-26 18:03:13 UTC
Permalink
In oracle:

SPOOL filename.txt
Select * from customer;
SPOOL OFF

Results are piped to filename.txt


How do I do this from the psql command line?


John J. Penrod, OCP
Oracle/EnterpriseDB Database Administrator
St. Jude Children's Research Hospital<http://www.stjude.org/stjude/v/index.jsp?vgnextoid=f2bfab46cb118010VgnVCM1000000e2015acRCRD&plt=STJGENSEGOOGL0000009&gclid=CM6Imp6I0Z0CFSMNDQodNXLerQ>
262 Danny Thomas Place, MS 0574
Memphis, TN 38105
Phone: (901) 595-4941
FAX: (901) 595-2963
***@stjude.org




________________________________
Email Disclaimer: www.stjude.org/emaildisclaimer
Kevin Kempter
2009-10-26 21:03:25 UTC
Permalink
Post by Penrod, John
SPOOL filename.txt
Select * from customer;
SPOOL OFF
Results are piped to filename.txt
How do I do this from the psql command line?
John J. Penrod, OCP
Oracle/EnterpriseDB Database Administrator
St. Jude Children's Research
Hospital<http://www.stjude.org/stjude/v/index.jsp?vgnextoid=f2bfab46cb1180
10VgnVCM1000000e2015acRCRD&plt=STJGENSEGOOGL0000009&gclid=CM6Imp6I0Z0CFSMND
QodNXLerQ> 262 Danny Thomas Place, MS 0574
Memphis, TN 38105
Phone: (901) 595-4941
FAX: (901) 595-2963
________________________________
Email Disclaimer: www.stjude.org/emaildisclaimer
psql
postgres=# \o file.out
postgres=# select * from customer;
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Raymond O'Donnell
2009-10-26 21:06:22 UTC
Permalink
Post by Penrod, John
SPOOL filename.txt
Select * from customer;
SPOOL OFF
Results are piped to filename.txt
How do I do this from the psql command line?
\g <filename> will execute the query and send the result to <filename>.


Ray.
--
Raymond O'Donnell :: Galway :: Ireland
***@iol.ie
--
Sent via pgsql-general mailing list (pgsql-***@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Loading...