trying to write a many-to-many type function.

From: Eric Davies <Eric(at)barrodale(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: trying to write a many-to-many type function.
Date: 2006-04-27 20:00:32
Message-ID: 7.0.1.0.0.20060427125626.01d1fbd0@barrodale.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)barrodale(dot)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
**********************************************

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Joachim Zobel 2006-04-27 21:19:57 [Announce] mod_sqil: an RDMS => XML mapper apache module
Previous Message Bruno Wolff III 2006-04-27 19:54:40 Re: Commit rules or Commit trigger