Unix Technical Forum

Passing multiple rows to a function?

This is a discussion on Passing multiple rows to a function? within the pgsql Novice forums, part of the PostgreSQL category; --> I know that you can pass rows/records to a function but what about a few rows? Is that possible? ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Novice

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-17-2008, 09:45 PM
Vitaly Belman
 
Posts: n/a
Default Passing multiple rows to a function?

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.

--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent@hotmail.com
Yahoo!: VitalyBe

---------------------------(end of broadcast)---------------------------
TIP 3: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that your
message can get through to the mailing list cleanly

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-17-2008, 09:45 PM
Michael Fuhr
 
Posts: n/a
Default Re: Passing multiple rows to a function?

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/i...orial-agg.html
http://www.postgresql.org/docs/8.0/i...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/i...ive/xaggr.html
http://www.postgresql.org/docs/8.0/i...aggregate.html

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 04-17-2008, 09:45 PM
Vitaly Belman
 
Posts: n/a
Default Re: Passing multiple rows to a function?

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/Ar...x?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@fuhr.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/i...orial-agg.html
> http://www.postgresql.org/docs/8.0/i...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/i...ive/xaggr.html
> http://www.postgresql.org/docs/8.0/i...aggregate.html
>
> --
> Michael Fuhr
> http://www.fuhr.org/~mfuhr/
>



--
ICQ: 1912453
AIM: VitalyB1984
MSN: tmdagent@hotmail.com
Yahoo!: VitalyBe

---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?

http://archives.postgresql.org

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

« SSL use | (NONE) »

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:19 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com