这些都是提供给我PostgreSQL函数
create type IR as (pattern_number integer, uoc_number integer);
我目前正在进行的类型定义为:
create or replace function q1(pattern text, uoc_threshold integer)
returns setof IR
as $$
BEGIN
RETURN QUERY
select count(code) from temp where code like $1;
RETURN QUERY
select count(code) from temp where code like $1 and uoc > $2;
END;
$$ language plpgsql;
我的输出要求是这样的: 查询: -
select *
from q1('ECO%', 6);
pattern_number | uoc_number
80 | 5
我收到一条错误消息:
ERROR: structure of query does not match function result type
DETAIL: Returned type bigint does not match expected type integer in column 1.
CONTEXT: PL/pgSQL function q1(text,integer) line 3 at RETURN QUERY
我该如何解决这个问题?
你的函数返回一个(BIGINT)列两行。你想要一行记录的单个列。 –
我做对了吗?你需要'从temp中选择count(代码),其中代码像$ 1'那样作为pattern_number并且'选择count(代码)从临时代码像$ 1和uoc> $ 2'那样的uoc_number?..我用代码添加了答案 - sic? –
@VaoTsun是的。这正是我想要的,但你的答案似乎不能解决错误 –