I have an edge_table containing start_id and start_geom column. I want to make one function which will take integer array as input (starts). In between the function, the array values will be checked with the start_ids of edge_table. If matches, then corresponding start_geom value will be send to st_makeline function. I have made following query but it is having syntax error near 'IN'.
CREATE OR REPLACE FUNCTION ids_to_linegeom (starts int[])
RETURNS geometry AS $BODY$
DECLARE
i integer;
res geometry;
BEGIN
select st_makeline(geom) from (
FOREACH i IN ARRAY $1
LOOP
SELECT start_geom AS geom
FROM edge_table
WHERE start_id = starts[i];
END LOOP;
)into res;
RETURN res;
END;
$BODY$ LANGUAGE plpgsql;
Example of edge_table:
start_id start_geom
81608 01010000007368912D8B622341E5D022EBEAF65A41
81557 010100000085EB51F89C0723418B6CE7DB9F8E5A41
189898 01010000006F1283C0A093214179E926F1A1005B41
80952 0101000000666666E67F832341F2D24DBA38B45A41
I have postgresql 9.6.