我尝试使用以下代码创建存储过程:
CREATE OR REPLACE FUNCTION public.get_paycheck(empl_id varchar, lmt integer, offst integer)
RETURNS TABLE(
request_id varchar
, nip varchar
, email varchar
, request_date timestamp with time zone
, salary_month date
, salary_year float
, status integer
, created_time timestamp with time zone)
language plpgsql stable
as $function$
BEGIN
return query
select
trp.request_id
,e.nip
,trp.email
,trp.request_date
,trp.salary_month
,date_part('year', trp.salary_month)
,trps.status
,trps.created_time
from tr_request_paycheck trp
join tr_request_paycheck_status trps on trps.request_id = trp.request_id
join ms_empl e on e.empl_id = trp.empl_id
where case
when $1 is not null and $1 <> '' then trp.empl_id = $1
else true
end
group by 1,2,3,4,5,6,7,8
LIMIT $2
OFFSET $3;
end;
$function$;
每当我执行它时,我都会收到错误
结构查询与结果类型
不匹配
即使我匹配表格中的所有类型。
任何人都可以帮我解决这个问题吗?
答案 0 :(得分:1)
这就是我最终的结果:
+---------------+--------------------------+-----------------------------------------+------------------+
| Column | Function Expects | You Passed | Which is of type |
+---------------+--------------------------+-----------------------------------------+------------------+
| request_id | varchar | tr_request_paycheck.request_ID | Varchar(255) |
| nip | varchar* | ms_empl.nip | Undefined* |
| email | varchar | tr_request_paycheck.email | varchar(255) |
| request_date | timestamp with time zone | tr_request_paycheck.request_date | timestamptz(28) |
| salary_month | date | tr_request_paycheck.salary_month | Date |
| salary_year | float | date_part('year', trp.salary_month) | Double Precision |
| status | integer | tr_request_paycheck_Status.status | Int4 |
| created_time | timestamp with time zone*| tr_request_paycheck_Status.Created_Time | Time(8)( |
+---------------+--------------------------+-----------------------------------------+------------------+