| From: | Gary Stainburn <gary(dot)stainburn(at)ringways(dot)co(dot)uk> |
|---|---|
| To: | Wayne Johnson <wdtj(at)yahoo(dot)com> |
| Cc: | "pgsql-interfaces" <pgsql-interfaces(at)postgresql(dot)org> |
| Subject: | Re: Calling psql from a shell script |
| Date: | 2001-06-28 14:18:00 |
| Message-ID: | 01062815180000.21902@gary.ringways.co.uk |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-interfaces |
Hi Wayne,
There should be no problems using psql in shell scripts. I do it to provide
HTML output in some of my early cgi's (although I now use Perl/DBI).
I think you can get psql to squirt out the data in kinda CSV format by
setting the delimiters that it should use. It's a long time since I did
anything like that, but I think it's got something to do with the \pset
commands.
The way I do it is to pass the commands to psql through STDIN using a heredoc
inside the shell script, and then use \o to direct the output and send STDOUT
to the bit bucket. Using the -q option to psql to quiet the startup and
prompt outputs, you could do it with STDOUT directly.
Gary
On Thursday 28 June 2001 1:44 am, you wrote:
> I am writing some shell scripts that need to access Postgresql.
>
> What is the best way to select a record and have shell variables set to
> the results.
>
> Is there a way to get psql to output data in quoted CSV?
>
> TIA.
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl
--
Gary Stainburn
This email does not contain private or confidential material as it
may be snooped on by interested government parties for unknown
and undisclosed purposes - Regulation of Investigatory Powers Act, 2000
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Eduardo Kotujansky | 2001-06-28 18:45:56 | JDBC- need to compile postgresql |
| Previous Message | Jean-Sébastien ANDUJAR | 2001-06-28 09:21:33 | libpq on windows |