Search Postgresql Archives

Re: Properly handling aggregate in nested function call

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Matt Magoffin <postgresql.org@xxxxxxx> writes:
> Any other ideas I could look into?

Per the old saw, when you can't see the problem, it usually means
you're looking in the wrong place.  I looked at the SQL declaration
of the function [1], and saw:

CREATE OR REPLACE FUNCTION
vec_agg_mean_finalfn(internal)
RETURNS bigint[]
AS 'aggs_for_vecs', 'vec_agg_mean_finalfn'
LANGUAGE c;

Of course what this function is actually returning is numeric[].
There is some code such as array_out that will look at the
element type OID embedded in the array value, and do the right
thing.  But other code will believe the function's declared
result type, and that sort of code will go wrong.

I see from your C code that you're hoping to make this stuff
somewhat polymorphic.  The simplest way to do that, and maybe
the best, is to make multiple SQL aliases for the same
C function, and then multiple aggregate declarations on top
of that.  Alternatively you can declare one set of polymorphic
functions and aggregates, in which case you'll need to closely
study the stuff about the finalfunc_extra option [2].

			regards, tom lane

[1] https://github.com/SolarNetwork/aggs_for_vecs/blob/9e742cdc32a113268fd3c1f928c8ac724acec9f5/aggs_for_vecs--1.3.0.sql#L1342
[2] https://www.postgresql.org/docs/current/xaggr.html#XAGGR-POLYMORPHIC-AGGREGATES






[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux