Re: redirecting query statement and output to a marked up file, using psql - Mailing list pgsql-general

From Bosco Rama
Subject Re: redirecting query statement and output to a marked up file, using psql
Date
Msg-id 4D4C3B6F.7010508@boscorama.com
Whole thread Raw
In response to Re: redirecting query statement and output to a marked up file, using psql  (Wim Bertels <wim.bertels@khleuven.be>)
List 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.

pgsql-general by date:

Previous
From: Bob Price
Date:
Subject: Re: how to avoid repeating expensive computation in select
Next
From: Carlos Mennens
Date:
Subject: Remove Role Membership