环境
系统平台:N/A
版本:5.6.5,4.3.4,4.7.7
症状
使用聚合函数报错如下:
highgo=# select sum('1');
ERROR: function sum(unknown) is not unique
第1行select sum('1');
^
提示: Could not choose a best candidate function. You might need to add explicit type casts.
highgo=# select avg('1');
ERROR: function avg(unknown) is not unique
第1行select avg('1');
^
提示: Could not choose a best candidate function. You might need to add explicit type casts.
问题原因
在 HGDB 中聚合函数只允许 SMALLINT、 INT、 BIGINT、 REAL、 DOUBLE PRECISION、 NUMERIC、 INTERVAL数据类型,或者通过::转义为以上类型。
解决方案
方法一:
highgo=# select sum(1);
sum
-----
1
(1 行记录)
highgo=# select avg(1);
avg
------------------------
1.00000000000000000000
(1 行记录)
方法二:
highgo=# select sum('1'::int);
sum
-----
1
(1 行记录)
highgo=# select avg('1'::NUMERIC);
avg
------------------------
1.00000000000000000000
(1 行记录)
1444

被折叠的 条评论
为什么被折叠?



