Systems

Calling a Python LP-solver from a PostgreSQL function

Prepare the database by installing PL/Python and a function: CREATE EXTENSION IF NOT EXISTS plpythonu; CREATE OR REPLACE FUNCTION hello_lp() RETURNS float[] AS $$ import subprocess output = subprocess.Popen ( [ “/Library/Frameworks/Python.framework/Versions/2.7/bin/python”, “/usr/local/trystuff/hello_lp.py” ], stdout = subprocess.PIPE, stderr = subprocess.STDOUT ).communicate()[0] # Parse string of comma-separated floats return map(lambda x: float(x), output.split(“,”)) $$ LANGUAGE plpythonu;

Calling a Python LP-solver from a PostgreSQL function Read More »