Last active
February 16, 2021 18:01
-
-
Save midwire/5952fc33736971b093ef72f490728a62 to your computer and use it in GitHub Desktop.
[Access Environment Variables With Postgres] Use environment variables with postgresql #postgres
This file contains hidden or 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
-- Before starting postgres server | |
-- export ENVNAME='whatever' | |
-- pg_ctl -D /usr/local/var/postgres [etc...] start | |
DROP TABLE IF EXISTS env; | |
DROP TABLE IF EXISTS env_tmp; | |
CREATE TEMP TABLE env_tmp(e text); | |
CREATE TEMP TABLE env(k text, v text); | |
COPY env_tmp ( e ) FROM PROGRAM 'env'; | |
INSERT INTO env | |
SELECT (regexp_split_to_array(e,'={1,1}'))[1], | |
(regexp_match(e, '={1,1}(.*)'))[1] | |
FROM env_tmp; | |
SELECT * FROM env WHERE k = 'ENVNAME'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment