[postgis-users] Problem using set-returning functions

Mark Cave-Ayland m.cave-ayland at webbased.co.uk
Mon Mar 27 03:03:31 PST 2006

> -----Original Message-----
> From: postgis-users-bounces at postgis.refractions.net [mailto:postgis-users-
> bounces at postgis.refractions.net] On Behalf Of Markus Schaber
> Sent: 27 March 2006 11:42
> To: PostGIS Users Discussion; PostgreSQL SQL List
> Subject: [postgis-users] Problem using set-returning functions
> Hi,
> I'm cross-posting this to the plpgsql list:
> We've run into a small problem creating a set-returning function for
> PostGIS in PostgreSQL 8.1.0:
> CREATE OR REPLACE FUNCTION generate_x (geom geometry)
> RETURNS SETOF double precision AS
>     index integer;
>     FOR index IN 1 .. npoints(geom) LOOP
> 	RETURN NEXT X(geometryn(geom,index));
>     END LOOP;
> Now, trying to use this function yields the following error:
> navteq=# select foo,generate_x(bar) from test;
> ERROR:  set-valued function called in context that cannot accept a set
> CONTEXT:  PL/pgSQL function "generate_x" line 5 at return next

Hi Markus,

Yup, as you probably already know, you need to do: SELECT * FROM
generate_x(bar) for a SRF. My guess would be that plpgsql is quite strict on
this test, whereas the C functions probably are not.... not sure whether the
behaviour is well defined though :(. Probably worth a question about this on

Kind regards,


WebBased Ltd
17 Research Way

T: +44 (0)1752 797131
F: +44 (0)1752 791023


This email and any attachments are confidential to the intended recipient
and may also be privileged. If you are not the intended recipient please
delete it from your system and notify the sender. You should not copy it or
use it for any purpose nor disclose or distribute its contents to any other

More information about the postgis-users mailing list