trying to write a many-to-many type function. - Mailing list pgsql-general

From Eric Davies
Subject trying to write a many-to-many type function.
Date
Msg-id 7.0.1.0.0.20060427125626.01d1fbd0@barrodale.com
Whole thread Raw
Responses Re: trying to write a many-to-many type function.  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-general
Hi,

I'd like to write a PostgreSQL server function (ideally in C) that takes a set of objects and returns 1 or more rows from each object, such that the rows returned can be cast to a desired rowtype. The structure of the returned rows depends on additional arguments. For example, I'd like to be able to write a function like the 'getMetaData' function shown below:
psql>select oid, getMetaData(myobject, "x,y,z")::t(x float, y float, c float) from mytable;
        93939 | (3,4,5)
        93939 | (3,4,9)
        93939 | (3,4,2)
        93939 | (4,3,1)
        93940 | (4,3,1)
        93940 | (3,1,4)

What I've tried:
By following the examples in the contrib directory, I managed to write a function that returned "setof record", but I can only cast its results if the function is in the from clause, ie:
        select   * from getMetaData('some text...'::myobjecttype) as t(x float, y float, c float);
Which limits me to calling the function with a single object.

As far as I can see, you can't write a set returning function that takes a set as input, as in
      select getMetaData( select * from mytable);

Is a function of the type I'm trying to write even possible in PostgreSQL?

**********************************************
Eric Davies, M.Sc.
Barrodale Computing Services Ltd.
Tel: (250) 472-4372 Fax: (250) 472-4373
Web: http://www.barrodale.com
Email: eric@barrodale.com
**********************************************
Mailing Address:
P.O. Box 3075 STN CSC
Victoria BC Canada V8W 3W2

Shipping Address:
Hut R, McKenzie Avenue
University of Victoria
Victoria BC Canada V8W 3W2
**********************************************


pgsql-general by date:

Previous
From: Bruno Wolff III
Date:
Subject: Re: Commit rules or Commit trigger
Next
From: Joachim Zobel
Date:
Subject: [Announce] mod_sqil: an RDMS => XML mapper apache module