How can I use an environment variable in a Postgres function?
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 for that particular platform.)