Bruce Momjian wrote:
What had me really confused was the first release item:

Allow polymorphic SQL functions (Joe)

How does an SQL function query the data types passed to it?  Once I
saw that I thought I didn't underestand what polymorphic functions
were.

It doesn't need to. For example:


CREATE OR REPLACE FUNCTION makearray(anyelement, anyelement) returns
anyarray as 'select ARRAY[$1, $2]' language sql;

regression=# select makearray(1,2);
 makearray
-----------
 {1,2}
(1 row)

regression=# select makearray('a'::text,'b');
 makearray
-----------
 {a,b}
(1 row)


<listitem><para>Allow user defined aggregates to use polymorphic
functions (Joe)</para> <listitem><para>Allow polymorphic user defined
aggregates  (Joe)</para></listitem>

These seem like duplicates.

They aren't. The first says you could create an aggregate with defined base and state datatypes, but where the state/final functions might be polymorphic. The second says that the base and state types might be polymorphic.

Are polymorphic functions currently most useful for aggregates?  Why
would someone want polymorphic aggregates? That is what I was hoping
for.

Well, one example is a calculation aggregate (let's say median) which
you might want to use for any numeric data type. Or an array accumulator, e.g.


CREATE AGGREGATE myagg1
(
  BASETYPE = float8,
  SFUNC = array_append,
  STYPE = float8[],
  INITCOND = '{}'
);
CREATE AGGREGATE

CREATE AGGREGATE myagg1p
(
  BASETYPE = anyelement,
  SFUNC = array_append,
  STYPE = anyarray,
  INITCOND = '{}'
);
CREATE AGGREGATE


Joe



---------------------------(end of broadcast)--------------------------- TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to [EMAIL PROTECTED] so that your message can get through to the mailing list cleanly

Reply via email to