Skip to content

Instantly share code, notes, and snippets.

@davidradernj
Created September 9, 2016 16:55
Show Gist options
  • Save davidradernj/2912c6bd69942ee0581f5cd47fe456e0 to your computer and use it in GitHub Desktop.
Save davidradernj/2912c6bd69942ee0581f5cd47fe456e0 to your computer and use it in GitHub Desktop.
plpython to read environment variable from PostgreSQL
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