错误:声明为返回my_fn的函数中的返回类型不匹配

时间:2019-07-10 09:14:45

标签: postgresql

当我从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 =(

0 个答案:

没有答案
相关问题