Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bt4jK-0002QZ-2z for pgsql-general@arkaria.postgresql.org; Sun, 09 Oct 2016 03:24:50 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bt4jJ-0006HX-HK for pgsql-general@arkaria.postgresql.org; Sun, 09 Oct 2016 03:24:49 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1bt4h1-0003ch-6n for pgsql-general@postgresql.org; Sun, 09 Oct 2016 03:22:27 +0000 Received: from [195.159.176.226] (helo=blaine.gmane.org) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bt4gu-0006Dg-PZ for pgsql-general@postgresql.org; Sun, 09 Oct 2016 03:22:26 +0000 Received: from list by blaine.gmane.org with local (Exim 4.84_2) (envelope-from ) id 1bt4gY-000718-Tf for pgsql-general@postgresql.org; Sun, 09 Oct 2016 05:21:58 +0200 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-general@postgresql.org From: Seb Subject: custom average window function failure Date: Sat, 08 Oct 2016 22:21:30 -0500 Organization: Church of Emacs Lines: 65 Message-ID: <87int2qkat.fsf@gmail.com> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@blaine.gmane.org User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.5 (gnu/linux) Cancel-Lock: sha1:mbbEtmZY0eDiOYwJ/ApKJ20V3ZM= X-Host-Lookup-Failed: Reverse DNS lookup failed for 195.159.176.226 (failed) X-Pg-Spam-Score: -0.2 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-general Precedence: bulk Sender: pgsql-general-owner@postgresql.org Hello, Until I upgraded to PostgreSQL 9.6, a custom average function was working well as a window function. It's meant to average a composite type: CREATE TYPE public.angle_vectors AS (x double precision, y double precision); COMMENT ON TYPE public.angle_vectors IS 'This type holds the x (sine) and y (cosine) components of angle(s).'; The average function: CREATE OR REPLACE FUNCTION public.angle_vectors_avg(angle_vectors_arr angle_vectors[]) RETURNS vector AS $BODY$ DECLARE x_avg double precision; y_avg double precision; magnitude double precision; angle_avg double precision; BEGIN SELECT avg(x) INTO x_avg FROM unnest(angle_vectors_arr) irows; SELECT avg(y) INTO y_avg FROM unnest(angle_vectors_arr) irows; magnitude := sqrt((x_avg ^ 2.0) + (y_avg ^ 2.0)); angle_avg := degrees(atan2(x_avg, y_avg)); IF (angle_avg < 0 ) THEN angle_avg := angle_avg + 360.0; END IF; RETURN (angle_avg, magnitude); END $BODY$ LANGUAGE plpgsql STABLE COST 100; COMMENT ON FUNCTION public.angle_vectors_avg(angle_vectors[]) IS 'This function computes the average angle from an array of concatenated angle_vectors data type singletons. It returns vector data type.'; And the aggregate: CREATE AGGREGATE public.avg(angle_vectors) ( SFUNC=array_append, STYPE=angle_vectors[], FINALFUNC=angle_vectors_avg ); Query below used to work in PostgreSQL 9.5: SELECT "time", avg((random(), random())::angle_vectors) over w from generate_series('2016-10-08'::timestamp, '2016-10-10'::timestamp, '5 hours') as t("time") window w as (partition by date_trunc('day', "time") order by "time"); but is now failing with the following message in 9.6: ERROR: input data type is not an array ********** Error ********** ERROR: input data type is not an array SQL state: 42804 Any thoughts on what has changed that is leading to this failure? -- Seb -- Sent via pgsql-general mailing list (pgsql-general@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-general