Re: Properly handling aggregate in nested function call

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Properly handling aggregate in nested function call
Дата
Msg-id 846904.1639619001@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Properly handling aggregate in nested function call  (Matt Magoffin <postgresql.org@msqr.us>)
Ответы Re: Properly handling aggregate in nested function call
Список pgsql-general
Matt Magoffin <postgresql.org@msqr.us> 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



В списке pgsql-general по дате отправления:

Предыдущее
От: "David G. Johnston"
Дата:
Сообщение: Re: Why can't I have a "language sql" anonymous block?
Следующее
От: Дмитрий Иванов
Дата:
Сообщение: Re: Best Strategy for Large Number of Images