public inbox for [email protected]  
help / color / mirror / Atom feed
From: Joe Conway <[email protected]>
To: Bruce Momjian <[email protected]>
Cc: Tatsuo Ishii <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: [email protected]
Cc: PostgreSQL-documentation <[email protected]>
Subject: Re: Annotated release notes
Date: Fri, 31 Oct 2003 14:10:26 -0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <[email protected]>
References: <[email protected]>

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




view thread (62+ messages)  latest in thread

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: [email protected]
  Cc: [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected], [email protected]
  Subject: Re: Annotated release notes
  In-Reply-To: <[email protected]>

* 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