Search Postgresql Archives

Re: 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]

 



On 04/10/10 20:51, andrew harvey wrote:
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`"

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!

This probably won't work:
  echo $command | cut -f 2,4,5
This probably will:
  echo "$command" | cut -f 2,4,5

I hate shell - I always spend hours trying to get quoting to work properly.

Oh, for the archives Andrew is probably using a command like:
  psql -t --no-align --field-separator=$'\011'
That turns the header and footer off (tuples only) and sets the output to unaligned tab-separated columns.

--
  Richard Huxton
  Archonet Ltd

--
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