From: | Seb <spluque(at)gmail(dot)com> |
---|---|
To: | pgsql-sql(at)postgresql(dot)org |
Subject: | creating a new aggregate function |
Date: | 2014-03-03 17:16:38 |
Message-ID: | 87iorvurrd.fsf@net82.ceos.umanitoba.ca |
Views: | Whole Thread | Raw Message | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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
From | Date | Subject | |
---|---|---|---|
Next Message | David Johnston | 2014-03-03 17:35:59 | Re: creating a new aggregate function |
Previous Message | ALMA TAHIR | 2014-03-03 11:32:02 | Re: Function Issue |