GitHub - pgsql-tw/envfdw: envFDW is a forign data wrapper for processing environment variables (original) (raw)

envFDW

Sample

postgres=# select * from envfdw;
        var         |             val
--------------------+-----------------------------
 PG_OOM_ADJUST_FILE | /proc/self/oom_score_adj
 PG_GRANDPARENT_PID | 917
 PGLOCALEDIR        | /usr/share/locale
 PGSYSCONFDIR       | /etc/postgresql-common
 LANG               | en_US.UTF-8
 PWD                | /
 PGDATA             | /var/lib/postgresql/11/main
 LC_COLLATE         | en_US.UTF-8
 LC_CTYPE           | en_US.UTF-8
 LC_MESSAGES        | en_US.UTF-8
 LC_MONETARY        | C
 LC_NUMERIC         | C
 LC_TIME            | C
 abc                | 1
 def                | 2
(15 rows)

Installation

Platform (Tested)

Install PostgreSQL and Multicorn

# apt-get install postgresql-11 postgresql-11-python3-multicorn

OR

# apt-get install postgresql-12 postgresql-12-python3-multicorn

Install envFDW

Usages

CREATE EXTENSION multicorn;
CREATE SERVER envfdw_srv FOREIGN DATA WRAPPER multicorn OPTIONS ( wrapper 'multicorn.envFDW.FDW' );
CREATE FOREIGN TABLE envfdw ( var text, val text ) SERVER envfdw_srv;
SELECT count(*) FROM envfdw; -- Count the table
SELECT * FROM envfdw; -- List all environment variables
INSERT INTO envfdw (var, val) VALUES ('abc', '1'), ('def', '2'); -- Add two new environment variables
UPDATE envfdw SET val='3' WHERE var='abc'; -- Set a new value to specified environment variables
DELETE FROM envfdw WHERE var='def'; -- Unset environment variables