Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKWU6-0002DT-Et for pgsql-sql@arkaria.postgresql.org; Mon, 03 Mar 2014 17:16:58 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1WKWU5-0008BV-I6 for pgsql-sql@arkaria.postgresql.org; Mon, 03 Mar 2014 17:16:57 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKWU2-00087X-Fu for pgsql-sql@postgresql.org; Mon, 03 Mar 2014 17:16:54 +0000 Received: from plane.gmane.org ([80.91.229.3]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1WKWU0-0003xS-N6 for pgsql-sql@postgresql.org; Mon, 03 Mar 2014 17:16:54 +0000 Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1WKWTy-0001YL-SQ for pgsql-sql@postgresql.org; Mon, 03 Mar 2014 18:16:50 +0100 Received: from net82.ceos.umanitoba.ca ([130.179.67.82]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 03 Mar 2014 18:16:50 +0100 Received: from spluque by net82.ceos.umanitoba.ca with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 03 Mar 2014 18:16:50 +0100 X-Injected-Via-Gmane: http://gmane.org/ To: pgsql-sql@postgresql.org From: Seb Subject: creating a new aggregate function Date: Mon, 03 Mar 2014 11:16:38 -0600 Organization: Church of Emacs Lines: 33 Message-ID: <87iorvurrd.fsf@net82.ceos.umanitoba.ca> Mime-Version: 1.0 Content-Type: text/plain X-Complaints-To: usenet@ger.gmane.org X-Gmane-NNTP-Posting-Host: net82.ceos.umanitoba.ca User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) Cancel-Lock: sha1:8bGah56aEN6rvsXGl0CwHbext7A= X-Pg-Spam-Score: -1.0 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org Hi, I'm trying to implement an aggregate function to calculate the average angle from one or more angles and corresponding magnitudes. So my first step is to design a function that decomposes the angles and magnitudes and returns the corresponding x and y vectors, and the following works does this: ---<--------------------cut here---------------start------------------->--- CREATE OR REPLACE FUNCTION decompose_angle(IN angle numeric, IN magnitude numeric, OUT x numeric, OUT y numeric) RETURNS record AS $BODY$ BEGIN x := sin(radians(angle)) * magnitude; y := cos(radians(angle)) * magnitude; END; $BODY$ LANGUAGE plpgsql STABLE COST 100; ALTER FUNCTION decompose_angle(numeric, numeric) OWNER TO sluque; COMMENT ON FUNCTION decompose_angle(numeric, numeric) IS 'Decompose an angle and magnitude into x and y vectors.'; ---<--------------------cut here---------------end--------------------->--- Before moving on to writing the full aggregate, I'd appreciate any suggestions to understand how to go about writing an aggregate for the above, that would return the average x and y vectors. Cheers, -- Seb -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql