aggregate function

From: Viktor Bojović <viktor(dot)bojovic(at)gmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: aggregate function
Date: 2010-08-03 14:38:51
Message-ID: AANLkTimo+SiM1VKiNM5V9tO4YMewn9+EoGV6NdJOpx+3@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I am trying to make aggregate function of existing function which looks like
this.
CREATE OR REPLACE FUNCTION "grafika"."pov_sphere" (x numeric, y numeric, z
numeric, rad numeric, pigment varchar) RETURNS varchar AS
$body$
DECLARE
_pov varchar;
BEGIN
_pov:='sphere {<'||x||','||y||','||z||'>,'||rad||' '||pigment ||'}';
return _pov;
END;
$body$
LANGUAGE 'plpgsql'
IMMUTABLE
RETURNS NULL ON NULL INPUT
SECURITY INVOKER
COST 100;

Aggregate should concatenate results of pov_sphere using this function
below.
CREATE OR REPLACE FUNCTION "public"."concat" (varchar, varchar) RETURNS
varchar AS
$body$
DECLARE
t varchar;
BEGIN
IF character_length($1) > 0 THEN
t = $1 || $2;
ELSE
t = $2;
END IF;
RETURN t;
END;
$body$
LANGUAGE 'plpgsql'
VOLATILE
CALLED ON NULL INPUT
SECURITY INVOKER
COST 100;

I tried to write this part below, but something is wrong (ERROR: function
grafika.pov_sphere(character varying, numeric, numeric, numeric, numeric,
character varying) does not exist) so I wanted to ask if someone knows how
to solve this problem.

CREATE AGGREGATE "grafika"."agg_pov_sphere" (NUMERIC, NUMERIC, NUMERIC,
NUMERIC, VARCHAR) (
SFUNC = "grafika"."pov_sphere",
STYPE = "varchar",
FINALFUNC = "public"."grp_concat"
);

Thanx in advance.
--
---------------------------------------
Viktor Bojović
---------------------------------------
Wherever I go, Murphy goes with me

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Tom Lane 2010-08-03 14:48:25 Re: aggregate function
Previous Message Andreas 2010-08-03 02:58:31 Help Need some hindsight