首页 > 解决方案 > 错误:声明返回 my_fn 的函数中的返回类型不匹配

问题描述

当我从我的 fn 回来时table,一切正常:

RETURNS table (o order_bt, c order_detail_bt, p price, ic item_cost)

但是当我重写我的 fn 以返回相同列的类型时

CREATE TYPE my_fn AS (o order_bt, c order_detail_bt, p price, ic item_cost)

RETURNS SETOF my_fn

我得到错误:

ERROR:  return type mismatch in function declared to return my_fn
DETAIL:  Final statement returns too many columns.

功能:

CREATE or replace FUNCTION "my_fn" ()
 RETURNS SETOF my_fn
 LANGUAGE sql
 STABLE
 AS $$
    SELECT o, od, sp, ic
    FROM order_bt o 
    LEFT JOIN order_detail_bt od ON od.order_id = o.id
    LEFT JOIN calc_point() sp ON sp.id = o.point_id
    LEFT JOIN table_fn() ic ON ic.fn_id = t.fn_id
    ...
$$

类型有什么问题my_fn

UPD

如果我重写:

SELECT (o, od, sp, ic)::my_fn

然后我得到

ERROR:  cannot cast type record to my_fn
LINE 6:  SELECT (o, od, sp, ic)::my_fn
                           ^
DETAIL:  Input has too many columns.

无法理解为什么完全相同的列适用于RETRUNS TABLE=(

标签: postgresql

解决方案


推荐阅读