postgresql - 错误:声明返回 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
=(
解决方案
推荐阅读
- python - 如何部署训练有素的 VGG-16 模型,使用 python 什么是最好的和免费的选项
- https - javax.net.ssl.SSLHandshakeException:com.ibm.jsse2.util.h:PKIX 路径构建失败
- tensorflow - .infer() 嵌入等效于 layersModel
- reactjs - 为什么 d3 中的 scale.ticks(number) 不能按预期工作?
- powershell - 无法在 PowerShell 中运行的脚本中声明方法
- elasticsearch - 如何选择分片和副本的数量 Elasticsearch
- python - 过滤器的python数据框
- amazon-web-services - 如何从 lambda 函数调用秘密管理器
- python - Pyserial 包不会从 COM 端口读取所有数据(始终只读取 6000 到 6150 字节)
- wordpress - 如何在 woocomerce 中创建自定义“添加到购物车”按钮