Re: redirecting query statement and output to a marked up file, using psql

From: Bosco Rama <postgres(at)boscorama(dot)com>
To: Wim Bertels <wim(dot)bertels(at)khleuven(dot)be>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: redirecting query statement and output to a marked up file, using psql
Date: 2011-02-04 17:46:23
Message-ID: 4D4C3B6F.7010508@boscorama.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Wim Bertels wrote:
>
> \qecho doenst interpret parameters it just echo text, in this case 'ECHO
> queries'

Seems like you had two problems and I didn't see any reference to the second
one initially. The first was the output of \echo going to the wrong place
which is fixed by using \qecho.

The second problem is that you are looking to have the variable 'ECHO' replaced
in the \qecho command with its current value. This is done using the variable
substitution syntax (i.e. the variable name within a pair of colons) like this:
\set ECHO Hello
\o testfile.txt
\qecho :ECHO: world
\q

Will cause the testfile.txt file to have a line that reads:
Hello world

HTH

Bosco.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Carlos Mennens 2011-02-04 17:51:36 Remove Role Membership
Previous Message Bob Price 2011-02-04 16:08:18 Re: how to avoid repeating expensive computation in select