Postgres width_bucket: 函数 width_bucket(integer, numeric[]) 不存在

Postgres width_bucket: function width_bucket(integer, numeric[]) does not exist

当我 运行 将整数数组作为第二个参数传递给 width_bucket 的查询时,我期望得到结果,例如:

select width_bucket(5, array[0, 1, 2, 3, 4, 5, 6, 7, 8] )

但是如果这个数组包含这样的十进制数:

select width_bucket( 5, array[0, 1.1, 2, 3, 4, 5, 6, 7, 8] )

我收到错误:

ERROR:  function width_bucket(integer, numeric[]) does not exist
LINE 1: select width_bucket( 5, array[0, 1.1, 2, 3, 4, 5, 6, 7, 8] )
               ^

我的用例是我正在使用 this function to calculate my data's breaks, which won't always be integers (and I've seen used elsewhere used with width_bucket in that codebase,所以我不确定为什么它在这里不起作用。

如何让 width_bucket 接受非整数数组?

[编辑添加 link 到 width_bucket 函数的 Postgres 文档,它说它接受“anycompatiblearray”,虽然我没有看到“兼容”数组类型列表在哪里已定义。]

此处的错误信息具有误导性。问题不是 width_bucket 不支持数值数组,而是它似乎不支持操作数和阈值之间的类型不匹配。

所有这些工作和return相同的值:

select width_bucket( 5.0, array[0, 1.1, 2, 3, 4, 5, 6, 7, 8] )
select width_bucket( 5::numeric, array[0, 1.1, 2, 3, 4, 5, 6, 7, 8] )