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.
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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.