Thread: Writing Result to Disk (psql)

Writing Result to Disk (psql)

From
ryan@paymentalliance.net
Date:
Is it possible to write the result of a SELECT statement to disk from
psql?

Thanks!

-r

Re: Writing Result to Disk (psql)

From
Jason Earl
Date:
Yes it is.  Check out the \o option.  For example:

processdata=> \o foobar
processdata=> select * from maintent;

Will put the output from the query "select * from
maintent" into the file foobar.  You might also find
the \f and \t options to be useful.  Try typing in \?
at the psql prompt for more information.

--- ryan@paymentalliance.net wrote:
> Is it possible to write the result of a SELECT
> statement to disk from
> psql?
>
> Thanks!
>
> -r
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to
majordomo@postgresql.org


__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

Re: Writing Result to Disk (psql)

From
Peter Eisentraut
Date:
ryan@paymentalliance.net writes:

> Is it possible to write the result of a SELECT statement to disk from
> psql?

\o filename
select things;
\o    (reset to terminal)

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


Re: Writing Result to Disk (psql)

From
"Len Morgan"
Date:
>Is it possible to write the result of a SELECT statement to disk from
>psql?

\o <filename>
<SELECT STATEMENT>
\o

Make sure you provide a complete path to the <filename> so you can find it
later!  :-)

len morgan


RE: Writing Result to Disk (psql)

From
"Tamsin"
Date:
in psql i use:
\o filename
to send all output to a file, then run the select statement, then just
\o
to stop sending output to the file.
is that what you meant?
tamsin


> -----Original Message-----
> From: pgsql-general-owner@postgresql.org
> [mailto:pgsql-general-owner@postgresql.org]On Behalf Of
> ryan@paymentalliance.net
> Sent: 14 May 2001 17:07
> To: pgsql-general@postgresql.org
> Subject: [GENERAL] Writing Result to Disk (psql)
>
>
> Is it possible to write the result of a SELECT statement to disk from
> psql?
>
> Thanks!
>
> -r
>
> ---------------------------(end of broadcast)---------------------------
> TIP 1: subscribe and unsubscribe commands go to majordomo@postgresql.org
>

Re: Writing Result to Disk (psql)

From
Justin Clift
Date:
Hi all,

Out of interest, you can output directly to attached printers, serial
ports, etc using the same format :

\o /dev/lp0

\o /dev/ttyS0

\o /dev/hdd4   <-- Don't do this one!

etc

Makes it interesting, especially in combination with outputting binary
data, etc.  Have to be careful to set your alignment correctly though,
else certain things won't work.

:-)

Regards and best wishes,

Justin Clift