加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql – 无法确定多态类型,因为输入的类型为“unknown”

发布时间:2020-12-12 06:54:35 所属栏目:MsSql教程 来源:网络整理
导读:我有一个查询,输出为 Could not determine polymorphic type because input has type “unknown” 查询: select ( array_to_string(array_agg(name),','))::text as name,path from(select 'fullpath' as Path,null as id,'' as name from tblabc where key
我有一个查询,输出为

Could not determine polymorphic type because input has type “unknown”

查询:

select ( array_to_string(array_agg(name),','))::text as name,path 
from(select 'fullpath' as Path,null as id,'' as name 
     from tblabc where key = 'key1' and value = '1' 
    ) as e 
group by path;

我有一个postgres数据库

解决方法

这里的问题是”??名称实际上没有为值指定类型.它是未知类型,PostgreSQL通常会推断出真正的类型,例如你要插入的列或者传递给它的函数.

在这种情况下,您将它传递给array_agg,这是一个polymorphc函数.它可以接受伪类型任意元素的输入,这实际上只是意味着“在运行时弄清楚它”.

PostgreSQL仍然可以解决它,除了array_to_string实际上并没有将text []作为输入.它需要任何数组 – 另一种多态类型,就像数组的任何元素一样.

因此查询中没有任何内容可以告诉PostgreSQL这是什么类型.它可能猜到你的意思是文字,但它有点太挑剔了.所以它抱怨.该问题简化为:

regress=> SELECT array_to_string(array_agg(''),');
ERROR:  could not determine polymorphic type because input has type "unknown"

要解决此问题,请编写一个类型文字:

TEXT '' AS name

或使用演员表:

CAST('' AS text) AS name

或PostgreSQL简写:

''::text

例子:

regress=> SELECT array_to_string(array_agg(TEXT ''),');
 array_to_string 
-----------------

(1 row)

regress=> SELECT array_to_string(array_agg(''::text),');
 array_to_string 
-----------------

(1 row)

regress=> SELECT array_to_string(array_agg(CAST('' AS text)),');
 array_to_string 
-----------------

(1 row)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读