0

我有一个类似的查询:

select
      coalesce(s.import_date, r.import_date) as import_date,
      coalesce(s.bedrooms, r.bedrooms) as bedrooms,
      coalesce(s.ptype, r.ptype) as property_type,
      s.s_price,
      s.s_transactions,
      ....
      r.r_rent,
      ....
from
(
    select

       sc.import_date,
       sc.bedrooms,
       sc.ptype,

       percentile_cont(array[0.25,0.5,0.75,0.9]) within group (order by sc.asking_price) filter(where sc.price > 0) as s_price,

       sum(1) filter(where sc.sold_price > 0) as s_transactions,

       ......

       from prices sc
       where sc.ptype = 'F' and  sc.bedrooms = 2 and st_Intersects('010300002.....'::geometry,sc.geom)
       and sc.import_date between '2012-01-01' and '2019-01-01'
       group by sc.import_date, sc.bedrooms, sc.property_type
) s
full join
(
    select
       rc.import_date,
       rc.bedrooms,
       rc.ptype,

       percentile_cont(array[0.25,0.5,0.75,0.9]) within group (order by rc.rent) filter(where rc.rent > 0) as r_rent,

      .....

       from rents rc
       where rc.ptype = 'F' and  rc.bedrooms = 2 and st_Intersects('010300002....'::geometry,rc.geom)
       and rc.import_date between '2012-01-01' and '2019-01-01'
       group by rc.import_date, rc.bedrooms, rc.property_type
) r
on r.import_date = s.import_date;

当我对 Citus/Postgres-11 上的分布式表运行它时,我得到:

ERROR: unsupported aggregate function percentile_cont

有没有办法解决这个限制?

4

1 回答 1

1

AFAIK 没有简单的解决方法。

您始终可以将所有数据拉到协调器并在那里计算百分位数。但是,不建议在同一个查询中执行此操作。

SELECT percentile_cont(array[0.25,0.5,0.75,0.9]) within group (order by r.order_col)
FROM
(
    SELECT order_col, ...
    FROM rents
    WHERE ...
) r
GROUP BY ...

该查询会将内部子查询返回的所有数据拉到协调器并计算协调器中的百分位数。

于 2019-03-12T10:37:37.120 回答