stored procedure: RETURNS record

From: InterRob <rob(dot)marjot(at)gmail(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: stored procedure: RETURNS record
Date: 2009-09-25 16:34:48
Message-ID: 671e36b0909250934u40e001cbge9ad1197a4a3de77@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Dear list,
I am trying to find out whether I can use the "record" type as a polymorphic
return type to return multiple columns, to be determined at runtime. In
fact, I'm trying to write a function that provides a generic implementation
of some deserialization of a certain field.

The prototype of the function I came up with, is as follows:
>> CREATE FUNCTION deserialize(the_table t1) RETURNS record << etc. etc. >>
;

It is intended to return multiple fields in an anonymous row: only at time
of invocation it is known what fields will this row consist of...

The function is used in the following statement:

>> SELECT * FROM (SELECT deserialize( t1 ) FROM t1) ss;

Unfortunately, this results in ONE row, with ONE column. E.g.:

MYDB=# select * from (SELECT deserialize(kvp) FROM kvp) ss;
deserialize
-----------
(1,2)
(1 row)

I guess I am seeking to prototype the anonymous row layout in the above SQL
statement?

Hope you have any idea,
regards,

Rob

Responses

Browse pgsql-general by date

  From Date Subject
Next Message John R Pierce 2009-09-25 16:39:41 Re: Delphi connection ?
Previous Message David W Noon 2009-09-25 15:36:43 Re: UPDATE statement with syntax error doesn't raise a warning?