Re: Polymorphic "setof record" function?

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Polymorphic "setof record" function?
Date: 2009-01-14 19:34:04
Message-ID: 20090114203404.18456f4a@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, 14 Jan 2009 11:46:29 -0500
"Merlin Moncure" <mmoncure(at)gmail(dot)com> wrote:

> On 1/13/09, Christian Schröder <cs(at)deriva(dot)de> wrote:
> > Hi list,
> > I have written a function that returns a setof record. The
> > function has a table name as a parameter and the resulting
> > records have the same structure as this table. Is there any easy
> > way to specify this when I call the function? If the table has
> > many columns then it's annoying to specify all of them.
> > I need something like:
> > select * from myfunc('mytable') as x(like mytable)
> > or
> > select * from myfunc('mytable') as x(mytable%TYPE)
> >
> > Is there any solution for PostgreSQL 8.2?

> Unfortunately to the best of my knowledge there is no way to do
> this. I think what you want is to have sql functions that
> specialize on type in the way that templates do in C++.

> This is _not_ the same as polymorhphic functions(anyelement, etc),
> because you would _end_up_with_as_separate_plan_per_type_ (and
> other reasons). Polymorphic functions are more similar to how
> inheritance in c++ works...you operate on the 'base' type.

> The type inferring operator (%type) is only part of the problem,
> you need to be able to create functions that it is known to the
> planner that it's template style:
>
> IMHO, this is a better abstraction than our current anyX
> pseudotypes, outside of the anyarray tricks.

I still haven't got the time to use them, but wouldn't refcursor
help?
Unfortunately I didn't find very enlightening examples of refcursors
use around.

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Raymond O'Donnell 2009-01-14 19:35:58 Re: Change empty database from ASCII to UTF-8 encoded
Previous Message Thom Brown 2009-01-14 19:14:10 Change empty database from ASCII to UTF-8 encoded