Problem using set-returning functions

From: Markus Schaber <schabi(at)logix-tt(dot)com>
To: PostGIS Users Discussion <postgis-users(at)postgis(dot)refractions(dot)net>, PostgreSQL SQL List <pgsql-sql(at)postgresql(dot)org>
Subject: Problem using set-returning functions
Date: 2006-03-27 10:41:32
Message-ID: 4427C15C.5070905@logix-tt.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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
'DECLARE
index integer;
BEGIN
FOR index IN 1 .. npoints(geom) LOOP
RETURN NEXT X(geometryn(geom,index));
END LOOP;
END
' LANGUAGE 'plpgsql' IMMUTABLE STRICT;

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

However, it is fine to call other set returning functions in the same
context:

navteq=# select foo,dump(bar) from test;
foo | dump
-----+--------------------------------------------------
42 | ({1},0101000000000000000000F03F0000000000000040)
42 | ({2},010100000000000000000008400000000000001040)
42 | ({3},010100000000000000000014400000000000001840)
23 | ({1},01010000000000000000001C400000000000002040)
(4 rows)

navteq=# select foo,x(geometryn(bar,generate_series(1,npoints(bar))))
FROM test;
foo | x
-----+---
42 | 1
42 | 3
42 | 5
23 | 7
(4 rows)

(This third query is equal to what I expected the failing query to do.)

The table "test" looks as follows;

navteq=# \d test
Table "public.test"
Column | Type | Modifiers
--------+----------+-----------
foo | integer |
bar | geometry |

navteq=# select foo,asText(bar) from test;
foo | astext
-----+-------------------------
42 | MULTIPOINT(1 2,3 4,5 6)
23 | MULTIPOINT(7 8)
(2 rows)

I'm shure its a small detail I've blindly ignored, but I'm stuck ATM.

Thanks,
Markus
--
Markus Schaber | Logical Tracking&Tracing International AG
Dipl. Inf. | Software Development GIS

Fight against software patents in EU! www.ffii.org www.nosoftwarepatents.org

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Markus Schaber 2006-03-27 13:21:05 Re: [postgis-users] Problem using set-returning functions
Previous Message Bryce Nesbitt 2006-03-26 21:47:34 Bitfields always atomic? Other way to store attributes?