I run two different queries. This one works well
with t(n) as(
values
(1),
(1),
(1),
(2),
(10)
)
select
width_bucket(n,array[1,3,6,15]) g,
count(*)
from t
group by g
order by g
but when I run this (real) query, it reports error on bucket
with data as (
select
vendor_id,
count(distinct pi.id) as cnt
from payment_invoice_items as pii
join payment_invoices as pi
on pii.invoice_id = pi.id
and pii.deleted_at isnull
group by vendor_id
)
select
width_bucket(data.cnt, array[1,10,20,30,40,100,200,400]) as grp,
count(*)
from data
group by grp
order by grp
The data.cnt is a one column of integer data. why does this report error?
[42883] ERROR: function width_bucket(bigint, integer[]) does not exist Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Thanks
The data.cnt is a one column of integer dataNo,COUNTreturns aBIGINT, so you will have to explicitly cast it toINTEGERin thewidth_bucketfunction.