Execute text in Postgresql database as Python code -
if have text saved in postgresql database there way execute text python code , potentially have update same database?
- that sounds terrifying.
- yes, plpy
pl/python extension postgres lets write functions in python. may have install extension package manager or may have been bundled in when installed postgres (this depends on how installed postgres apt-get install postgresql-plpython-9.1 in debian).
to enable extension in database first use psql run:
create extension plpythonu now can specify functions python write function execute code like:
create function eval_python(code text) returns integer $$ eval(code) return 1 $$ language plpythonu; and execute every code field in my_table like:
select eval_python(code) my_table; read docs on pl/python more details on how interact db python.
Comments
Post a Comment