Re: postgres via shell scripts

Поиск
Список
Период
Сортировка
От Jim Mercer
Тема Re: postgres via shell scripts
Дата
Msg-id 20001006111902.P22260@reptiles.org
обсуждение исходный текст
Ответ на Re: postgres via shell scripts  (bmccoy@chapelperilous.net)
Ответы Re: postgres via shell scripts  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-general
On Fri, Oct 06, 2000 at 11:17:08AM -0400, bmccoy@chapelperilous.net wrote:
> On Fri, 6 Oct 2000, Mike Sears wrote:
> > Is there away to access a postgres database using a shell script, like bash
> > or korn?
>
> You can use
>
> psql -c <query>
>
> or
>
> psql -f <filename>
>
> to do command-line stuff inside of a script.  But then you have to figure
> out how to parse the result.  You're probably better off going the next
> step and using Perl.

i generally use:

psql -A -t -q -d database -c "sql query" > tempfile
if [ $? -ne 0 ] ; then
     echo command failed
     exit
fi
awk -F\| -f script.awk tempfile
.....

there is a commandline options somewhere to change he field seperator, but
i forget it now.

you could do it all in one line and pipe the psql into awk/whatever.

but i've found that checking the return status of psql before actually using
the data is a useful thing.  8^)

--
[ Jim Mercer                 jim@reptiles.org              +1 416 410-5633 ]
[          Reptilian Research -- Longer Life through Colder Blood          ]
[  Don't be fooled by cheap Finnish imitations; BSD is the One True Code.  ]

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

Предыдущее
От: bmccoy@chapelperilous.net
Дата:
Сообщение: Re: postgres via shell scripts
Следующее
От: Peter Eisentraut
Дата:
Сообщение: Re: postgres via shell scripts