我在 Ubuntu 12.04 上使用 Postgresql 9.1。
在一个plpgsql
函数中,我尝试连接setof
从另一个函数返回的类型。
有type pair_id_value
问题的创建与create type pair_id_value as (id bigint, value integer);
返回基本的函数setof pair_id_value
(稍后将被连接的那些)是这样的:
create or replace function compute_pair_id_value(id bigint, value integer)
returns setof pair_id_value
as $$
listResults = []
for x in range(0,value+1):
listResults.append({ "id": id, "value": x})
return listResults
$$
language plpython3u;
Run Code Online (Sandbox Code Playgroud)
这个直截了当的 plpython 代码应该很好,例如查询:select * from compute_pair_id_value(1712437,2);
返回很好:
id | value
---------------+-----------
1712437 | 0
1712437 | 1
1712437 | 2
(3 rows) …
Run Code Online (Sandbox Code Playgroud) postgresql stored-procedures plpgsql postgresql-9.1 set-returning-functions