Re: Outputting select into file. - Mailing list pgsql-general

From Dado Feigenblatt
Subject Re: Outputting select into file.
Date
Msg-id 3C20DAC6.2080101@wildbrain.com
Whole thread Raw
In response to Outputting select into file.  (Troy.Campano@LibertyMutual.com)
List pgsql-general
Lee Kindness wrote:

>Troy.Campano@LibertyMutual.com writes:
> > I have postgres 7 running on RedHat Linux.
> > I was wondering if you knew of a way to run a select and output it to a
> > file.
> > SELECT * FROM TABLE >> test.out
> > So that test.out would have the results from that SQL Statement.
>
>Either:
>
> SELECT * FROM table \g filename
>
>to just output to the file 'filename', or:
>
> select * from lineshoot \g |cat >> /solsolute/path/filename
>
>to append to the file. Both in psql, or:
>
> echo 'SELECT * FROM table' | psql database >> test.out
>
>from your terminal.
>
>Regards, Lee Kindness.
>
>---------------------------(end of broadcast)---------------------------
>TIP 4: Don't 'kill -9' the postmaster
>
>
or
psql -c "SELECT * from ...." | command
psql -c "SELECT * from ...." > file
psql -c "SELECT * from ...." >> file

You might want to
echo password | psql -c "query..." > file
but I rather type it when prompted
I used that once in a script, but then the password was clear to anyone
who had access to the script.
But there are ways to fix it if that's what you want.

--
Dado Feigenblatt                                 Wild Brain, Inc.
Technical Director                               (415) 216-2053
dado@wildbrain.com                               San Francisco, CA.




pgsql-general by date:

Previous
From: Paulo Jan
Date:
Subject: Re: Query hangs when getting too complex...
Next
From: Bruce Momjian
Date:
Subject: Re: Can't use subselect in check constraint