Re: Calling psql from a shell script

Поиск
Список
Период
Сортировка
От Gary Stainburn
Тема Re: Calling psql from a shell script
Дата
Msg-id 01062815180000.21902@gary.ringways.co.uk
обсуждение исходный текст
Ответ на Calling psql from a shell script  (Wayne Johnson <wdtj@yahoo.com>)
Список 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     


В списке pgsql-interfaces по дате отправления:

Предыдущее
От: Wayne Johnson
Дата:
Сообщение: Calling psql from a shell script
Следующее
От: "Eduardo Kotujansky"
Дата:
Сообщение: JDBC- need to compile postgresql