The query is like so:
CREATE TABLE Edge_Table AS
SELECT a.*gid,nextval('ty') AS edge_gid,
ST_SetSRID(ST_MakeLine(a.geom, getcentroids(a.gid)),4326) AS geom_line
FROM Points_table a;
where my getcentroids Function returns 8 nearest points to each point creating an edge with each one of them, the problem arises with duplicates as same edge is created from 1->2 and 2->1, how do I optimise this query itself as large data has to be processed, could index or UNIQUE constraint help?