gpt4 book ai didi

postgresql 函数返回多列

转载 作者:行者123 更新时间:2023-11-29 13:19:59 24 4
gpt4 key购买 nike

我对在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com