我对在 Postgres 中创建的函数的参数传递过程感到困惑:
create type IncorrectRecord as (pattern_number integer, uoc_number integer);
create or replace function text1(pattern text, uoc_threshold integer)
returns setof IncorrectRecord
as $$
begin
return next count(v1.code) as pattern_number, count(v2.code) as uoc_number
from (select * from q1_1 where code like pattern) as v1, (select
* from q1_1 where code like pattern and uoc > uoc_threshold) as v2;
return;
end
$$ language plpgsql;
我修改了一些,没有参数错误,但还是不行。 当我用
测试它时select *
from test1('ECO%', 8)
error: function returns two columns.
类型有问题吗?我该如何解决?
最佳答案
正如消息所说,您将返回两列。而是返回复合类型:
return next (
count(v1.code) as pattern_number, count(v2.code) as uoc_number
)::IncorrectRecord
关于postgresql 函数返回多列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43724183/