我正在编写以下 pgsql 程序:
CREATE OR REPLACE FUNCTION KNN(gid_ integer)
RETURNS Text AS $body$
DECLARE
row_ RECORD;
BEGIN
SELECT g1.gid As SOURCE, g2.gid As Neighbors FROM polygons as g1, polygons as g2 WHERE g1.gid = $1 and g1.gid <> g2.gid ORDER BY g1.gid,
ST_Distance(g1.the_geom,g2.the_geom) limit 5;
END
$body$
LANGUAGE plpgsql;
现在查询为提供给过程的每个参数值返回 5 行。我怎样才能返回这 5 行。此外,我如何为存储在表多边形中作为列 gid 的所有参数值执行该过程。请有人提供完整的代码。谢谢你。