From: Gary Stainburn <gary.stainburn@ringways.co.uk>
To: Wayne Johnson <wdtj@yahoo.com>
Cc: pgsql-interfaces <pgsql-interfaces@postgresql.org>
Subject: Re: Calling psql from a shell script
Date: Thu, 28 Jun 2001 15:18:00 +0100
Message-ID: <01062815180000.21902@gary.ringways.co.uk> (raw)
In-Reply-To: <3B3A7DEE.1FE009CE@yahoo.com>
References: <3B3A7DEE.1FE009CE@yahoo.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-interfaces@postgresql.org
Cc: gary.stainburn@ringways.co.uk, wdtj@yahoo.com
Subject: Re: Calling psql from a shell script
In-Reply-To: <01062815180000.21902@gary.ringways.co.uk>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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