Re: Multiple Parameters to an Aggregate Function

From: Joel Burton <joel(at)joelburton(dot)com>
To: Anthony Bouvier <anthony(at)developware(dot)com>
Cc: <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Multiple Parameters to an Aggregate Function
Date: 2001-10-17 17:51:13
Message-ID: Pine.LNX.4.30.0110171348180.24721-100000@temp.joelburton.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tue, 16 Oct 2001, Anthony Bouvier wrote:

> I can create an AGGREGATE but from what I can tell, the format of the
> sfunc can only have two parameters like so:
>
> sfunc_name(type,type)
>
> Where the first parameter is what was passed before, and the second
> parameter is the 'new' info to do stuff to. Is it not possible to do
> something similar to?:
>
> sfunc_name(type,type,type)
>
> So that I can pass the url and name to the AGGREGATE (so it can in turn
> pass it to the sfunc)? Where the sfunc could be something like so:
>
> CREATE FUNCTION link_agg (text,text,text)
> RETURNS text AS '
> return $_[0] . qq[<a href="http://www.domain.com/$_[0]"
> class="body_link">$_[1]</a><br>];
> ' LANGUAGE 'plperl';
>
> Because then I gain benefit of a stored procedure and cut the SQL in the
> script down to:
>
> SELECT link_agg(url,name) FROM link;
>
> Which will return the entire list at once, instead of needing the script
> to loop through multiple fetches.

I have a techdoc about using aggregate functions to create faster
web looping at

http://www.zope.org/Members/pupq/pg_in_aggregates

It was written w/examples in DTML, Zope's scripting language, rather than
in Perl/DBI, but you should be able to easily follow it.

Essentially, what you want to end up with is something like this:

SELECT make_into_li ( make_into_text ( url, name ) );

where make_into_text is the aggregate, and make_into_text is the
formatting function.

--

Joel BURTON | joel(at)joelburton(dot)com | joelburton.com | aim: wjoelburton
Independent Knowledge Management Consultant

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Burton 2001-10-17 17:53:38 Re: nvl() function
Previous Message Stephan Szabo 2001-10-17 17:47:45 Re: index problem