pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Matt Magoffin <postgresql.org@msqr.us>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: Properly handling aggregate in nested function call
Date: Wed, 15 Dec 2021 20:43:21 -0500
Message-ID: <846904.1639619001@sss.pgh.pa.us> (raw)
In-Reply-To: <AF8238C6-E34C-452E-8718-D90BB5E231E2@msqr.us>
References: <0005FD8A-0FBE-4D53-BBDE-7242A4DC525C@msqr.us>
	<559031.1639522278@sss.pgh.pa.us>
	<AF8238C6-E34C-452E-8718-D90BB5E231E2@msqr.us>

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...
[2] https://www.postgresql.org/docs/current/xaggr.html#XAGGR-POLYMORPHIC-AGGREGATES





view thread (6+ messages)  latest in thread

Message-ID: <846904.1639619001@sss.pgh.pa.us>
Permalink:  ../846904.1639619001@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/846904.1639619001@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, postgresql.org@msqr.us
  Subject: Re: Properly handling aggregate in nested function call
  In-Reply-To: <846904.1639619001@sss.pgh.pa.us>
  References: <0005FD8A-0FBE-4D53-BBDE-7242A4DC525C@msqr.us> <559031.1639522278@sss.pgh.pa.us> <AF8238C6-E34C-452E-8718-D90BB5E231E2@msqr.us> <846904.1639619001@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox