Re: [DOCS] Annotated release notes

Поиск
Список
Период
Сортировка
От Joe Conway
Тема Re: [DOCS] Annotated release notes
Дата
Msg-id 3FA2DDD2.7000002@joeconway.com
обсуждение исходный текст
Ответ на Re: [DOCS] Annotated release notes  (Bruce Momjian <pgman@candle.pha.pa.us>)
Список pgsql-hackers
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


В списке pgsql-hackers по дате отправления:

Предыдущее
От: Larry Rosenman
Дата:
Сообщение: Re: Regression Failure: CURRENT SOURCES/union&join
Следующее
От: Christopher Browne
Дата:
Сообщение: Re: 7.4RC1 planned for Monday