Helpful Information
 
 
Category: PostgreSQL Help
Functions And PostgreSQL

I was wondering if It is possible to return a whole recordset from a function. I managed to return one column, but what if I want to select several columns from a table.
This works fine with a view, but I have not found a way to pass parameters into a view...I need a little of both..
Any help anybody?

Thanks

I think functions, by nature, will only allow you to return one value. What are you trying to return that can't be done with a view?

I would just like to store my SQL statements in postgres so I can re-use them. Like a stored procedure in MS SQL (don't want to go there..). Call a function in the database and pass my parameters to it. In return I get the recordset.
For ex.
I pass a userid to a function and have it return all the users data to me in a recordset.
Sorry for not replying sooner...Have not been in here for a while.

Visit the PostgreSQL Cookbook. It is a website where they are starting a library of example functions for PostgreSQL: http://www.brasileiro.net/postgres/cookbook/

You might find some helpful examples there.

From Bruce Momjiam's book PostrgreSQL Introduction and Concepts:

"Although most functions return only one value, SQL functions can return multiple values using SETOF."

See http://www.ca.postgresql.org/docs/aw_pgsql_book/node164.html

Thanks. I will check those things out.










privacy (GDPR)