Writing Result to Disk (psql)

Started by Ryan Mahoneyalmost 25 years ago6 messagesgeneral
Jump to latest
#1Ryan Mahoney
ryan@paymentalliance.net

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

Thanks!

-r

#2Len Morgan
len-morgan@crcom.net
In reply to: Ryan Mahoney (#1)
Re: Writing Result to Disk (psql)

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

#3Peter Eisentraut
peter_e@gmx.net
In reply to: Ryan Mahoney (#1)
Re: Writing Result to Disk (psql)

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

#4Jason Earl
jdearl@yahoo.com
In reply to: Ryan Mahoney (#1)
Re: Writing Result to Disk (psql)

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/

#5Tamsin
tg_mail@bryncadfan.co.uk
In reply to: Ryan Mahoney (#1)
RE: Writing Result to Disk (psql)

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

Show quoted text

-----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

#6Justin Clift
justin@postgresql.org
In reply to: Tamsin (#5)
Re: Writing Result to Disk (psql)

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