postgresql 自定义aggregate function实现reduce

create or replace function lmy(first INTEGER, item INTEGER) returns INTEGER as $$
BEGIN
  return first * item;
END;
$$
LANGUAGE plpgsql;

create aggregate yml(INTEGER) (
  sfunc = lmy,
  stype = INTEGER,
  initcond = 1
);

isnp=# select i, yml(i) over (order by i) from generate_series(1,10) i;

iyml
11
22
36
424
5120
6720
75040
840320
9362880
103628800
    原文作者:dreambei
    原文地址: https://segmentfault.com/a/1190000007038509
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞