multiply(num) aggregate function in postgresql

≯℡__Kan透↙ 提交于 2019-12-10 09:54:02

问题


This could be incredibly simple by the documentation is quite on it. Is there a way to aggregate columns via multiplication operator in postgresql. I know i can do count(column) or sum(column), but is there a multiply(column) or product(column) function that i can use. If not, any ideas how to achieve it.

I'm using postgres 9.1

regards, Hassan


回答1:


Sure, just define an aggregate over the base multiplication function. E.g. for bigint:

CREATE AGGREGATE mul(bigint) ( SFUNC = int8mul, STYPE=bigint );

Example:

regress=> SELECT mul(x) FROM generate_series(1,5) x;
 mul 
-----
 120
(1 row)

See CREATE AGGREGATE



来源:https://stackoverflow.com/questions/21623282/multiplynum-aggregate-function-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!