Lists: | pgsql-general |
---|
From: | Troy(dot)Campano(at)LibertyMutual(dot)com |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | Outputting select into file. |
Date: | 2001-12-19 15:06:06 |
Message-ID: | 9534B16F750ED2118CF90008C724C4460C22235B@lmig-msg-20.lmig.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Hello,
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.
For example
SELECT * FROM TABLE >> test.out
So that test.out would have the results from that SQL Statement.
Thank you for your time,
Troy Campano
From: | Lee Kindness <lkindness(at)csl(dot)co(dot)uk> |
---|---|
To: | Troy(dot)Campano(at)libertymutual(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Outputting select into file. |
Date: | 2001-12-19 15:44:09 |
Message-ID: | 15392.46537.511719.871128@elsick.csl.co.uk |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Troy(dot)Campano(at)LibertyMutual(dot)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.
From: | Dado Feigenblatt <dado(at)wildbrain(dot)com> |
---|---|
To: | Troy(dot)Campano(at)libertymutual(dot)com |
Cc: | pgsql-general(at)postgresql(dot)org |
Subject: | Re: Outputting select into file. |
Date: | 2001-12-19 18:21:58 |
Message-ID: | 3C20DAC6.2080101@wildbrain.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Lists: | pgsql-general |
Lee Kindness wrote:
>Troy(dot)Campano(at)LibertyMutual(dot)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(at)wildbrain(dot)com San Francisco, CA.