Can a function return more then one table?

Started by Mike Christensenabout 14 years ago4 messagesgeneral
Jump to latest
#1Mike Christensen
mike@kitchenpc.com

I would like to write a function that returns one row from one table,
and about 10 rows or so from another table..

Is there a clean way to do this, or am I better off making two separate queries?

I'm thinking maybe I can use OUT parameters for the first table, and
the return value for the second table? However, I have no idea what
the syntax would be like.

Mike

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Mike Christensen (#1)
Re: Can a function return more then one table?

Hello

2012/1/11 Mike Christensen <mike@kitchenpc.com>:

I would like to write a function that returns one row from one table,
and about 10 rows or so from another table..

Is there a clean way to do this, or am I better off making two separate queries?

I'm thinking maybe I can use OUT parameters for the first table, and
the return value for the second table?  However, I have no idea what
the syntax would be like.

what is possible

* return setof refcursors
* use arrays instead tables and returns arrays (for tables less 10000 rows)

Regards

Pavel Stehule

Show quoted text

Mike

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Mike Christensen
mike@kitchenpc.com
In reply to: Pavel Stehule (#2)
Re: Can a function return more then one table?

2012/1/11 Mike Christensen <mike@kitchenpc.com>:

I would like to write a function that returns one row from one table,
and about 10 rows or so from another table..

Is there a clean way to do this, or am I better off making two separate queries?

I'm thinking maybe I can use OUT parameters for the first table, and
the return value for the second table?  However, I have no idea what
the syntax would be like.

what is possible

* return setof refcursors
* use arrays instead tables and returns arrays (for tables less 10000 rows)

Thanks! Both of these options sound feasible, I will play around with
some code and see what I can come up with.

Mike

#4Sergey Konoplev
gray.ru@gmail.com
In reply to: Pavel Stehule (#2)
Re: Can a function return more then one table?

On Wed, Jan 11, 2012 at 10:47 AM, Pavel Stehule <pavel.stehule@gmail.com> wrote:

* return setof refcursors
* use arrays instead tables and returns arrays (for tables less 10000 rows)

One more option is to use hstore plus populate_record().

Regards

Pavel Stehule

Mike

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

--
Sergey Konoplev

Blog: http://gray-hemp.blogspot.com
LinkedIn: http://ru.linkedin.com/in/grayhemp
JID/GTalk: gray.ru@gmail.com Skype: gray-hemp