我在下面的 SQL 代码中找不到错误的原因。请帮我!
CREATE OR REPLACE FUNCTION public.get_points(loc text)
RETURNS SETOF points_nearby AS
$BODY$
DECLARE
rec points_nearby;
points text[];
j int;
poi varchar;
length int;
BEGIN
points := string_to_array(loc, ',');
length := array_length(points, 1);
j = 1;
while j <= length
LOOP
poi := trim('SRID=4326;POINT('||points[j]||')');
FOR rec IN select "gid", "tb_elev" as elevation,
st_x("geom") as x,
st_y("geom")as y,
st_distance( poi::geometry, "geom" ) as distance
from
(
select *
from
"tb_elev"
where
st_within("geom" ,st_buffer(poi::geometry, 50) )
) as a order by distance limit 4
LOOP
RETURN NEXT rec;
END LOOP;
j := j + 1;
END LOOP;
RETURN;
END;
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100
ROWS 1000;`
select get_points('971317 2027702');
这是结果消息:
ERROR: parse error - invalid geometry
HINT: "971317" <-- parse error at position 7 within geometry
CONTEXT: PL/pgSQL function get_points(text) line 15 at FOR over SELECT rows