postgresql调用函数与错误的参数

时间:2018-01-09 10:59:20

标签: postgresql postgis

我声明了postgresql函数如下,这个函数只是计算kmeter中2点之间的距离

CREATE OR REPLACE FUNCTION show_places(ref refcursor,lat float8,lon float8, radius double precision) RETURNS refcursor AS $$
BEGIN
  OPEN ref FOR SELECT * FROM place p where ST_Distance(ST_Point(lon,lat)::geography,ST_Point(p.lon,p.lat)::geography) <= radius;    -- Open a cursor
  RETURN ref;                                                        
END;
$$ LANGUAGE plpgsql;

致电如下:

BEGIN;
SELECT show_places('cities_cur',44.379,-79.703,255621.82229418);
FETCH ALL IN "cities_cur";
COMMIT;

但我遇到了这个SQL异常:

enter image description here

1 个答案:

答案 0 :(得分:0)

变量和表列的相同名称变得混乱。只需更改变量的名称

CREATE OR REPLACE FUNCTION show_places(ref refcursor,v_lat float8,v_lon float8, radius double precision) RETURNS refcursor AS $$
BEGIN
  OPEN ref FOR SELECT * FROM place p where ST_Distance(ST_Point(v_lon,v_lat)::geography,ST_Point(p.lon,p.lat)::geography) <= radius;    -- Open a cursor
  RETURN ref;                                                        
END;
$$ LANGUAGE plpgsql;