查询的结构与函数结果类型不匹配

Vin*_*lla 0 postgresql

我想创建一个基本函数,它接受一个输入并抛出一个具有多列和多行的表作为输出。我为此编写了以下查询:

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 column 1. 
CONTEXT: PL/pgSQL function proc_name_1(text) line 3 at RETURN QUERY
Run Code Online (Sandbox Code Playgroud)

请帮忙。谢谢

McN*_*ets 5

似乎question_type定义为varchar(80)但你定义questiontext

只需将其转换为文本:

select question_type::text
Run Code Online (Sandbox Code Playgroud)