Record Separator with psql -c when output to a variable not a file!

Поиск
Список
Период
Сортировка
От andrew harvey
Тема Record Separator with psql -c when output to a variable not a file!
Дата
Msg-id 7a4987b8-f323-452e-a6dd-236affe2d6ca@x7g2000yqg.googlegroups.com
обсуждение исходный текст
Ответы Re: Record Separator with psql -c when output to a variable not a file!  (Richard Huxton <dev@archonet.com>)
Re: Record Separator with psql -c when output to a variable not a file!  (Martijn van Oosterhout <kleptog@svana.org>)
Re: Record Separator with psql -c when output to a variable not a file!  (Vick Khera <vivek@khera.org>)
Список pgsql-general
The default psql -c record separator is a newline when output is the
screen, console or a file. But what if I'm required to send output to
a variable and not to a file (or standard output?)


command="`psql  -c "SELECT * FROM pg_stat_database`"

when you retain the query result within the variable $command you need
to count all the fields in the entire output in order to select the
particular one that you want. (because the record separator newline
doesn't apply to within the variable named above) Therefore all the
sql output is bundled up into one string with very, very many fields.

It so happened that field 38 was the number of pages served from disk
for one of my databases and field 53 turned out to be the number of
pages served from cache for another one of my databases. But this is
hardly a sensible way of producing results!

Is there a more sensible way of formatting the sql output within the
specified variable I've called $command?

I know that, obviously, if you output the result of the sql query to a
file and then use grep and awk you could have wonderful output all the
time. But there is a specific requirement here to do all the
formatting from within a variable!

Thanks,

Andrew












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

Предыдущее
От: Adrian Klaver
Дата:
Сообщение: Re: How to data dump a table content to a CSV or XML format?
Следующее
От: Cédric Villemain
Дата:
Сообщение: Re: PG website testing