Re: Polymorphic "setof record" function?

From: Christian Schröder <cs(at)deriva(dot)de>
To: Merlin Moncure <mmoncure(at)gmail(dot)com>
Cc: PostgreSQL <pgsql-general(at)postgresql(dot)org>
Subject: Re: Polymorphic "setof record" function?
Date: 2009-01-15 09:57:02
Message-ID: 496F086E.5000900@deriva.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Merlin Moncure 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++.
>
That would certainly be the best solution, but I would also be happy
with some syntactic sugar: The function may still be declared as
returning a set of records, so that I would still have to declare their
actual return type in the query. However, I would like to have an easy
way to express: "the record will have the same structure as table x".

Regards,
Christian

--
Deriva GmbH Tel.: +49 551 489500-42
Financial IT and Consulting Fax: +49 551 489500-91
Hans-Böckler-Straße 2 http://www.deriva.de
D-37079 Göttingen

Deriva CA Certificate: http://www.deriva.de/deriva-ca.cer

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kenneth Lundin 2009-01-15 10:10:54 function to return both table row and varchar
Previous Message Richard Huxton 2009-01-15 09:47:41 Re: Autovacuum daemon terminated by signal 11