Thread: select into ...outfile

select into ...outfile

From
Clinton Adams
Date:
I need to generate text files from queries.  In mysql this was SELECT INTO
OUTFILE.  Is it a two step process with postgres - SELECT INTO TEMPORARY
TABLE then COPY TABLE?

/clinton


Re: select into ...outfile

From
Oliver Elphick
Date:
On Fri, 2002-03-01 at 22:50, Clinton Adams wrote:
>
> I need to generate text files from queries.  In mysql this was SELECT INTO
> OUTFILE.  Is it a two step process with postgres - SELECT INTO TEMPORARY
> TABLE then COPY TABLE?

That will work, but you cannot do much with the formatting.

The most direct way for you to do what you want is to use \o OUTFILE
from psql.  You can use other psql options to change the field
delimiters, if you want to export to a spreadsheet, for example; or you
can output in HTML or LaTeX format.

--
Oliver Elphick                                Oliver.Elphick@lfix.co.uk
Isle of Wight                              http://www.lfix.co.uk/oliver
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C

     "The LORD is my shepherd; I shall not want. He maketh
      me to lie down in green pastures: he leadeth me beside
      the still waters, he restoreth my soul...Surely
      goodness and mercy shall follow me all the days of my
      life; and I will dwell in the house of the LORD for
      ever."                    Psalms 23:1,2,6