我正在使用postgresql 9.6。 我建立了一个功能,我做了一个“选择”:
id = TD["new"]["id"]
qry = plpy.prepare ("SELECT (decode->>'key')::integer AS key FROM table where id = $1;", ["int"])
res= plpy.execute(qry,[id])
请求工作正常,但结果保持键和值,而不仅仅是值。 事实上,结果是这样的:{“key”:2937}
我只想要价值。
答案 0 :(得分:0)
结果对象模拟列表或字典对象。可以通过行号和列名访问结果对象。
create or replace function pf()
returns integer as $$
query = 'select 1 as 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