Re: Passing multiple rows to a function?

From: Vitaly Belman <vitalyb(at)gmail(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: Postgresql Novice <pgsql-novice(at)postgresql(dot)org>
Subject: Re: Passing multiple rows to a function?
Date: 2005-04-24 08:48:57
Message-ID: fa96e3c605042401487062e5ad@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

I am aware of the aggregate functions but that's not what I need.
Well, it was a bad example to what I really wanted to do, I guess :(
my bad.

I have a recursive table (id, name, parent_id) and I'd like to return
for a given id all its parents - an example to how to do this is given
here http://www.paragoncorporation.com/ArticleDetail.aspx?ArticleID=24.
However, unlike the example I don't want the function to return all
the parents in a string, but instead I want to use the "set returning
functions" to return a table of all the parent_ids. Now I am just
thinking about how to make it a recursive function.

Ideas will be welcome.

On 4/24/05, Michael Fuhr <mike(at)fuhr(dot)org> wrote:
> On Sun, Apr 24, 2005 at 03:00:55AM +0300, Vitaly Belman wrote:
> >
> > I know that you can pass rows/records to a function but what about a
> > few rows? Is that possible?
> >
> > For example, I'd like to send to a function a number of rows from the
> > "workers" table (e.g "select * from workers where age<10") and the
> > function will return their summed salary.
>
> See "Aggregate Functions" in the PostgreSQL Tutorial, and again in
> the "Functions and Operators" chapter. Here are links to documentation
> for the latest version of PostgreSQL:
>
> http://www.postgresql.org/docs/8.0/interactive/tutorial-agg.html
> http://www.postgresql.org/docs/8.0/interactive/functions-aggregate.html
>
> If you want to create your own aggregate functions, see "User-Defined
> Aggregates" in the "Extending SQL" chapter and the documentation
> for CREATE AGGREGATE:
>
> http://www.postgresql.org/docs/8.0/interactive/xaggr.html
> http://www.postgresql.org/docs/8.0/interactive/sql-createaggregate.html
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>

--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent(at)hotmail(dot)com
Yahoo!: VitalyBe

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Beto . 2005-04-24 23:08:25
Previous Message Michael Fuhr 2005-04-24 00:21:31 Re: Passing multiple rows to a function?