agora inbox for pgsql-sql@postgresql.org  
help / color / mirror / Atom feed
From: Seb <spluque@gmail.com>
To: pgsql-sql@postgresql.org
Subject: creating a new aggregate function
Date: Mon, 03 Mar 2014 11:16:38 -0600
Message-ID: <87iorvurrd.fsf@net82.ceos.umanitoba.ca> (raw)
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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



-- 
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql



view thread (7+ messages)  latest in thread

Message-ID: <87iorvurrd.fsf@net82.ceos.umanitoba.ca>
Permalink:  ../87iorvurrd.fsf@net82.ceos.umanitoba.ca/
Also on:    postgresql.org/message-id/87iorvurrd.fsf@net82.ceos.umanitoba.ca

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: spluque@gmail.com
  Subject: Re: creating a new aggregate function
  In-Reply-To: <87iorvurrd.fsf@net82.ceos.umanitoba.ca>

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

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