Reputation: 111
I'd like to send variable in psql into shell to do some tricky things with it there and use the result in psql again. See:
\set ENVIR `echo :HOST | cut -f2 -d-`
\echo :ENVIR
However, the psql variable seems to be not interpolating in backticks as I would expect: shell's echo :HOST
gives just :HOST
. Help, please.
Upvotes: 0
Views: 277
Reputation: 9157
You need to use \setenv
to export the psql variable to the shell:
\set HOST 'the-host-name'
\setenv HOST :HOST
\set ENVIR `echo $HOST | cut -f2 -d-`
\echo :ENVIR
produces:
host
Of course, your example can be done with postgres string functions, with no need for shelling out.
Upvotes: 1