I am working on PostGIS 2.5.3 and PostgreSQL 11.2
As seen in the example below, I have 3 LineString that I would like to Merge to form one single Linestring. The squares represent the vertices, so we see there isn't any vertex at the intersection of the green and the blue LineString. Currently the only option I found is to use
ST_Union(), which produce a MultiLineString since it simply merges the geometries without any special consideration.
Do you know a way to have the proper result, here a single LineString which crosses itself (as I would draw if I were to trace it manually) ?
EDIT : Improving from obchardon's answer, here is an example to work with :
SELECT ST_AsText(ST_LineMerge(ST_Union(geom))) FROM -- Three dummy LineString for the example (SELECT (ST_Dump(ST_GeomFromText('MULTILINESTRING((0 0,3 3),(3 3,1 3), (1 3, 3 2))'))).geom) AS T