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