Postgresql function plpython select json value -
i'm using postgresql 9.6. build function "selec"t :
id = td["new"]["id"] qry = plpy.prepare ("select (decode->>'key')::integer key table id = $1;", ["int"]) res= plpy.execute(qry,[id])
the request work fine, result hold key , value, not value. in fact, result : {"key":2937}
i want value.
the result object emulates list or dictionary object. result object can accessed row number , column name.
create or replace function pf() returns integer $$ query = 'select 1 key' rs = plpy.execute(query) plpy.notice(rs.__str__()) return rs[0]['key'] $$ language plpythonu; select pf(); notice: <plyresult status=5 nrows=1 rows=[{'key': 1}]> pf ---- 1
https://www.postgresql.org/docs/current/static/plpython-database.html
Comments
Post a Comment