Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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












-- 
Sent via pgsql-general mailing list (pgsql-general@xxxxxxxxxxxxxx)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux