Thread: export a select result in a file ?

export a select result in a file ?

From
"ctobini"
Date:
Hello,

I don't find in the PostgreSQL doc how to export a select result in a
text file.

Thanks if you can help me.

C. Tobini


Re: export a select result in a file ?

From
"A. Kretschmer"
Date:
am  04.10.2005, um  5:00:16 -0700 mailte ctobini folgendes:
> Hello,
>
> I don't find in the PostgreSQL doc how to export a select result in a
> text file.
>
> Thanks if you can help me.

You can use \o in psql to redirect the result to a file.

\o out.file


Regards, Andreas
--
Andreas Kretschmer    (Kontakt: siehe Header)
Heynitz:  035242/47212,      D1: 0160/7141639
GnuPG-ID 0x3FFF606C http://wwwkeys.de.pgp.net
 ===    Schollglas Unternehmensgruppe    ===

Re: export a select result in a file ?

From
Scott Marlowe
Date:
On Tue, 2005-10-04 at 07:00, ctobini wrote:
> Hello,
>
> I don't find in the PostgreSQL doc how to export a select result in a
> text file.

If you want to get the data without being IN psql (like in an automated
script) you can use the -tc switches ("t"uples only, run this
"c"ommand):

psql dbname -tc "select yabba from dabba where doo=1" > myfile.dat

If you're in psql, use \o for output.  \i does the same thing for input
from a file.