Re: Record Separator with psql -c when output to a variable not a file! - Mailing list pgsql-general

From Richard Huxton
Subject Re: Record Separator with psql -c when output to a variable not a file!
Date
Msg-id 4CAA45AE.50600@archonet.com
Whole thread Raw
In response to Record Separator with psql -c when output to a variable not a file!  (andrew harvey <a.andrewharvey@gmail.com>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Jeff Ross
Date:
Subject: psql \q hang
Next
From: Martijn van Oosterhout
Date:
Subject: Re: Record Separator with psql -c when output to a variable not a file!