[postgis-users] Returning multiple fields from a plpgsql function

Stephen Woodbridge woodbri at swoodbridge.com
Wed Jul 29 11:19:10 PDT 2009


Hi,

This is another slightly off topic, but maybe generally helpful inquiry.

I have a plpgsql function the does some spatial queries and returns 
results using a type like:

CREATE TYPE my_result AS
     (attr1 text,
      attr2 text,
      attr3 text,
      distance float,
      linkid int);


in the function:

DECLARE
     ret my_result;

then set the values of the fields like:

     ret.attr1 := attr1;
     ...

and return the results like:

     return ret;


later I do:

select my_function(x,y);

and get a result that looks like:

("attr1","attr2","attr3",102.2,1234567)

which all looks fine and dandy, except that I can not seem to access the 
individual fields. So for example if I want the value of my_result.attr1 
how would I get that? Is there a better way to do this?

Thanks,
   -Steve



More information about the postgis-users mailing list