Be aware that you will get a different answer if you decompose the points. Tehe closest point on the line might be between the vertex points.
– Nicklas AvénJan 22 '18 at 22:14

If that's what your looking for you're going to have to calculate the closest point on every line and see which one is closer for every point in the result set. That is to say, it's simply going to be slow (afaik)
– Evan CarrollJan 22 '18 at 23:47

@EvanCarroll thank you for you help. Never used a JOIN LATERAL and it is fantastic.
– tjmgisJan 23 '18 at 9:38