我想创建一个基本函数,它接受一个输入并抛出一个具有多列和多行的表作为输出。我为此编写了以下查询:
create or replace function proc_name_1 (store text)
returns table (question text , resp numeric , gendr text , resp_count integer)
as $$
begin
return query
select question_type , response, gender, sum(response_count)
from fashtagcompute.response_count
where store_id = store
group by question_type , response, gender ;
end ;
$$
language plpgsql ;
CREATE FUNCTION
Run Code Online (Sandbox Code Playgroud)
函数创建成功。但是,如果我尝试执行它,则会出现以下错误
select * from proc_name_1('ab1f47ff-5c96-46fb-b975-81bf92c01b63')
ERROR: structure of query does not match function result type
DETAIL: Returned type character varying(80) does not match expected type text in …Run Code Online (Sandbox Code Playgroud) postgresql ×1