我在plpgsql中完成了以下功能。它工作正常并且它返回'OK'
,但由于某种原因它在表中没有输入任何内容temp
。
CREATE OR REPLACE FUNCTION public.get_route(node integer[])
RETURNS character varying AS
$BODY$DECLARE
i int := 0;
_r record;
vertex int;
BEGIN
FOREACH i IN ARRAY node
LOOP
IF( i < (array_length(node, 1) - 1))
THEN
FOR _r IN EXECUTE 'select * from shortest_path(''
select id as id, source_id::int4 as source, target_id::int4 as target, cost, reverse_cost
from network_of_point'','|| node[i] ||','|| node[i+1] ||', true, true)'
LOOP
vertex := _r.vertex_id;
EXECUTE 'insert into temp
select nextval(''road_intersection_id_seq''), point
from distinct_network_point
where distinct_network_point.id ='|| vertex;
END LOOP;
i = i + 1;
END IF;
END LOOP;
RETURN 'OK';
END;$BODY$
以下是我用来调用该函数的 synatx:
select get_route('{2,7}')