Thread: Copy query results to a file

Copy query results to a file

From
Eduardo Vázquez Rodríguez
Date:
My purpose is to copy the results of a query to a file, how I do that?

Thanks in advenced

Attachment

Re: Copy query results to a file

From
Oliver Elphick
Date:
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@lfix.co.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