3

Let's say I have a windows user environment variable SOME_STRING.

Is it possible to use its value in a PL/pgSQL function?

If not, do I need to use an untrusted language (like PL/pythonu) or can I use a trusted one?

I am on PG 9.2

1

You can not access a environment variable directly; but you can access a custom configuration setting and set that to a value from the environment at startup. For example, you can pass the follow startup option using PGOPTIONS:

PGOPTIONS="-c 'custom.some_string=${SOME_STRING}'"

Note: the dot (.) in the name is important.

Then retrieve the value using current_setting:

SELECT current_setting('custom.some_string');

(I have tried this on Linux and found it to be working, it should be the same for Windows, but may need some slight modification to cater of that particular platform.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.