Search Postgresql Archives

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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxxxxxx
**********************************************
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
**********************************************



[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux