Re: Interpolation of environment variables in SQL at runtime? - Mailing list pgsql-general

From Joe Conway
Subject Re: Interpolation of environment variables in SQL at runtime?
Date
Msg-id 41856112.6040005@joeconway.com
Whole thread Raw
In response to Interpolation of environment variables in SQL at runtime?  (Andy Gimblett <A.M.Gimblett@swansea.ac.uk>)
List pgsql-general
Andy Gimblett wrote:
> Hopefully what I'm asking is fairly obvious.  But is it possible?  I
> can imagine some fairly unwiedly ways to do this involving
> preprocessing, but would involve jumping through lots of hoops, and
> I'd hope for a cleaner solution.  Environment variables seems the
> obvious "Unixy" approach...
>
> Surely people have hit this problem before?  How's it solved?

See plr_environ() in PL/R's pg_userfunc.c. You could probably rip it out
and use it standalone with reasonable ease (or perhaps modify it to
return a single requested environment variable).

Use it like this:

select value from plr_environ() where name = 'MANPATH';
            value
---------------------------
  /usr/local/pgsql-dev/man:
(1 row)

Joe

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Daylight Savings Time handling on persistent connections
Next
From: Bruno Lavoie
Date:
Subject: Suggested Triggers & Functions Naming Convention?