Обсуждение: Select dump

Поиск
Список
Период
Сортировка

Select dump

От
SG Edwards
Дата:
Hi,

Quick question for 10 points!

Is there a way to write the output of a select query to a file (I'm on a linux
platform)?

For example:

SELECT name, age, address from employee;

gives the result that I want to write to a text file:

John, 21, Edinburgh

Re: [despammed] Select dump

От
Andreas Kretschmer
Дата:
am  11.05.2005, um 14:15:10 +0100 mailte SG Edwards folgendes:
>
> Hi,
>
> Quick question for 10 points!
>
> Is there a way to write the output of a select query to a file (I'm on a linux
> platform)?
>
> For example:
>
> SELECT name, age, address from employee;
>
> gives the result that I want to write to a text file:

If you work with psql, you can use "\o FILE" to define a filename for
output. If you work in a shell a call psql, you can redirect the output.


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

Re: [despammed] Select dump

От
John DeSoi
Дата:
On May 11, 2005, at 9:34 AM, Andreas Kretschmer wrote:

> If you work with psql, you can use "\o FILE" to define a filename for
> output. If you work in a shell a call psql, you can redirect the
> output.

And see the psql documentation for the other options you need. You'll
want to set the field separator to a comma and turn on the "tuples
only" option to get rid of the headers and other information normally
in the output.

http://www.postgresql.org/docs/current/interactive/app-psql.html


John DeSoi, Ph.D.
http://pgedit.com/
Power Tools for PostgreSQL


Re: Select dump

От
Geoffrey
Дата:
SG Edwards wrote:
> Hi,
>
> Quick question for 10 points!
>
> Is there a way to write the output of a select query to a file (I'm on a linux
> platform)?
>
> For example:
>
> SELECT name, age, address from employee;
>
> gives the result that I want to write to a text file:

 From what interface?  You can do this from psql:

echo 'select foo from bar;' | psql database > select.out

--
Until later, Geoffrey