I have a plpgsql function in PostgreSQL 9.2 which returns a table. I try to find the distance between the point pairs which are I have in my database. But I am facing the error in the title of this question.
I wanted to do something like this:
CREATE OR REPLACE FUNCTION max_dis(which_tab text)
RETURNS TABLE(P1 geometry, P2 geometry, dis double precision) as
$$
DECLARE
my_row RECORD;
my_row2 RECORD;
BEGIN
FOR my_row IN EXECUTE ('SELECT * FROM '||which_tab) LOOP
--
FOR my_row2 IN EXECUTE ('SELECT * FROM '||which_tab) LOOP
SELECT ST_DISTANCE(my_row.the_geom, my_row2.the_geom)
INTO dis;
RETURN NEXT my_row,my_row2;
END LOOP;
END LOOP;
RETURN;
END ;
$$
LANGUAGE plpgsql VOLATILE STRICT;