I have shapefile/PostGIS table of points.

I want to connect them to form a single line.

When trying with PostGIS:

```
Select ST_MakeLine(points_table.geom) FROM points_table;

```

The problem is that because the points are not ordered, the line is crossing itself.

When trying in QGIS Points2One plugin - same issue.

After looking at the data - It seems that if connect each 2 closest points - the desired line will created.

[![enter image description here](https://i.stack.imgur.com/yfsfh.png)](https://i.stack.imgur.com/yfsfh.png)