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?

  1. that sounds terrifying.
  2. 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

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -