0

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.

1 Answer 1

1

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

Edit

Of course, your example can be done with postgres string functions, with no need for shelling out.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.