[英]postgreSQL pl/python how do I get the RETURNING from a query?
in this (vey condensed) query, how would one return the myfile_key from RETURNING? 在此(维压缩)查询中,如何从RETURNING返回myfile_key?
CREATE OR REPLACE FUNCTION myfunction (src int, OUT result int) AS $$
plan = plpy.prepare("INSERT INTO myfile VALUES (nextval('seq_myfile'),$1,$2)
RETURNING myfile_key", ["integer","integer"] )
$$ LANGUAGE plpythonu;
(where the first field inserted is myfile_key) (插入的第一个字段是myfile_key)
The code doesn't return the value to output, and haven't been able to query it as a standard python result, as in: 该代码不会将值返回给输出,并且无法将其作为标准python结果进行查询,如下所示:
result = rv[0]["myfile_key"]
I assume there is a call to plpy.execute
missing in your code. 我假设您的代码中缺少对plpy.execute
的调用。 You are in principle right to access the RETURNING
columns like rv[0]["myfile_key"]
. 您在访问原则上是正确RETURNING
样柱rv[0]["myfile_key"]
。 What's not working is the assignment to OUT
parameters in PL/Python. 在PL / Python中分配给OUT
参数无效。 I suggest that you rewrite your function without OUT
parameters using a normal return
statement. 我建议您使用正常的return
语句重写不带OUT
参数的函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.