pg.ddx.io pgsql-interfaces@postgresql.org mailing list archive
help / color / mirror / Atom feedCalling psql from a shell script
2+ messages / 2 participants
[nested] [flat]
* Calling psql from a shell script
@ 2001-06-28 00:44 Wayne Johnson <wdtj@yahoo.com>
0 siblings, 1 reply; 2+ messages in thread
From: Wayne Johnson @ 2001-06-28 00:44 UTC (permalink / raw)
To: wdtj@yahoo.com
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.
^ permalink raw reply [nested|flat] 2+ messages in thread
* Re: Calling psql from a shell script
@ 2001-06-28 14:18 Gary Stainburn <gary.stainburn@ringways.co.uk>
parent: Wayne Johnson <wdtj@yahoo.com>
0 siblings, 0 replies; 2+ messages in thread
From: Gary Stainburn @ 2001-06-28 14:18 UTC (permalink / raw)
To: Wayne Johnson <wdtj@yahoo.com>; +Cc: 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
^ permalink raw reply [nested|flat] 2+ messages in thread
end of thread, other threads:[~2001-06-28 14:18 UTC | newest]
Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2001-06-28 00:44 Calling psql from a shell script Wayne Johnson <wdtj@yahoo.com>
2001-06-28 14:18 ` Gary Stainburn <gary.stainburn@ringways.co.uk>
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox