Created
September 9, 2016 16:55
-
-
Save davidradernj/2912c6bd69942ee0581f5cd47fe456e0 to your computer and use it in GitHub Desktop.
plpython to read environment variable from PostgreSQL
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
create extension plpythonu; | |
create type py_environ_type as (name text, value text); | |
create or replace function py_environ(name varchar DEFAULT NULL) | |
returns setof py_environ_type | |
as $$ | |
import os | |
aev = [] | |
if name is None: | |
for k, v in os.environ.items(): | |
aev.append((k, v)) | |
else: | |
v = os.getenv(name) | |
if v is not None: | |
aev.append((name,v)) | |
return aev; | |
$$ language plpythonu | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment