Re: How do I pipe output from query to a file in PostgreSQL?

Lists: pgsql-general
From: "Penrod, John" <John(dot)Penrod(at)STJUDE(dot)ORG>
To: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: How do I pipe output from query to a file in PostgreSQL?
Date: 2009-10-26 18:03:13
Message-ID: 8172D639BA76A14AA5C9DE7E13E0CEBE02F442BC0D@SJMEMXMBS10.stjude.sjcrh.local
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

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
john(dot)penrod(at)stjude(dot)org

________________________________
Email Disclaimer: www.stjude.org/emaildisclaimer


From: Kevin Kempter <kevink(at)consistentstate(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: How do I pipe output from query to a file in PostgreSQL?
Date: 2009-10-26 21:03:25
Message-ID: 200910261503.25153.kevink@consistentstate.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On Monday 26 October 2009 12:03:13 Penrod, John wrote:
> 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=f2bfab46cb1180
> 10VgnVCM1000000e2015acRCRD&plt=STJGENSEGOOGL0000009&gclid=CM6Imp6I0Z0CFSMND
> QodNXLerQ> 262 Danny Thomas Place, MS 0574
> Memphis, TN 38105
> Phone: (901) 595-4941
> FAX: (901) 595-2963
> john(dot)penrod(at)stjude(dot)org
>
>
>
>
> ________________________________
> Email Disclaimer: www.stjude.org/emaildisclaimer
>

psql
postgres=# \o file.out
postgres=# select * from customer;


From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: "Penrod, John" <John(dot)Penrod(at)STJUDE(dot)ORG>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I pipe output from query to a file in PostgreSQL?
Date: 2009-10-26 21:06:22
Message-ID: 4AE60F4E.4020402@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Lists: pgsql-general

On 26/10/2009 18:03, Penrod, John wrote:
> 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?

\g <filename> will execute the query and send the result to <filename>.

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie