简体   繁体   English

postgreSQL pl / python如何从查询中获得RETURNING?

[英]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.

相关问题 Python3:使用Python连接到Postgresql数据库...如何获取结果查询以大熊猫数据帧中的行形式返回? - Python3: Connecting into postgresql database with Python… how do I get resulting query to return as rows in a pandas dataframe? 如何针对自定义的Postgresql(例如PG_CONFIG)构建和安装PL / Python? - How do I build and install PL/Python against a custom Postgresql (e.g. PG_CONFIG)? 如何将 postgresql 数据库的列放入 Python 列表中? - How do I get the columns of a postgresql database into a Python list? 如何从Python连接到Postgresql服务器? - How do I connect to Postgresql server from Python? PostgreSQL中的PL / Python - PL/Python in PostgreSQL 如何使用python将这些数据插入到postgresql中? - How do I insert this data into postgresql with python? PostgreSQL PL / Python如何在性能方面与Python之外的Python进行比较? - How does PostgreSQL PL/Python compare with Python outside it in terms of performances? 从PostgreSQL中的PL / Python函数调用plpgsql函数 - Call plpgsql Function from a PL/Python Function in PostgreSQL 如何在python中获取已解析查询字符串的值? - How do I get the values of a parsed query string in python? 如何在 mysql 连接器 python 查询中获得文字“%”? - How do I get a literal '%' in a mysql connector python query?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM