Re: Copy query results to a file

From: Oliver Elphick <olly(at)lfix(dot)co(dot)uk>
To: Eduardo Vázquez Rodríguez <evazquez(at)insys-corp(dot)com(dot)mx>
Cc: Postgres <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Copy query results to a file
Date: 2004-08-09 20:09:17
Message-ID: 1092082157.13140.342.camel@linda
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

On Mon, 2004-08-09 at 20:00, Eduardo Vázquez Rodríguez wrote:
> My purpose is to copy the results of a query to a file, how I do that?
>
> Thanks in advenced

$ psql -d mydb
mydb=# \o /path/to/file
mydb=# select ...;
mydb=# \o

In that case /path/to/file must be writable by the backend.

Alternatively,

$ psql -d mydb -c "select ..." > /path/to/file

If you are using Windows, the syntax of the latter method may be
different.

--
Oliver Elphick olly(at)lfix(dot)co(dot)uk
Isle of Wight http://www.lfix.co.uk/oliver
GPG: 1024D/A54310EA 92C8 39E7 280E 3631 3F0E 1EC0 5664 7A2F A543 10EA
========================================
"Be still before the LORD and wait patiently for him;
do not fret when men succeed in their ways, when they
carry out their wicked schemes."
Psalms 37:7

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Thiemo Kellner 2004-08-09 20:23:42 Re: [GENERAL] Error >>syntax error<< at >>$1<< at character 53
Previous Message Eduardo Vázquez Rodríguez 2004-08-09 19:00:50 Copy query results to a file