LineString Self-Intersection points

I'm trying to get all the points from a Self-Intersection LineString.

1. On LineString segments intersection with no vertex on intersection: ST_Intersection make the job;
2. Now, how catch the vertex intersection like image? Just crosses points...

Segments with 3 points each... nop, ST_Crosses dont work properly... :(

``````DROP FUNCTION IF EXISTS temp.ST_Segments3points(geometry);
CREATE OR REPLACE FUNCTION temp.ST_Segments3points(geom1 geometry)
RETURNS geometry
AS \$\$
DECLARE
i int;
n_points int;
newLines text  = 'MULTILINESTRING(';

BEGIN
newLines := newLines || '(' || ST_X(ST_PointN(geom1,1)) || ' ' || ST_Y(ST_PointN(geom1,1)) || ' ' || ST_Z(ST_PointN(geom1,1)) || ',';
newLines := newLines || ST_X(ST_PointN(geom1,2)) || ' ' || ST_Y(ST_PointN(geom1,2)) || ' ' || ST_Z(ST_PointN(geom1,2)) || ',';
newLines := newLines || ST_X(ST_PointN(geom1,3)) || ' ' || ST_Y(ST_PointN(geom1,3)) || ' ' || ST_Z(ST_PointN(geom1,3)) || '),';
FOR i IN 4..ST_NumPoints(geom1) LOOP
newLines := newLines || '(' || ST_X(ST_PointN(geom1,i-2)) || ' ' || ST_Y(ST_PointN(geom1,i-2)) || ' ' || ST_Z(ST_PointN(geom1,i-2)) || ',';
newLines := newLines || ST_X(ST_PointN(geom1,i-1)) || ' ' || ST_Y(ST_PointN(geom1,i-1)) || ' ' || ST_Z(ST_PointN(geom1,i-1)) || ',';
newLines := newLines || ST_X(ST_PointN(geom1,i)) || ' ' || ST_Y(ST_PointN(geom1,i)) || ' ' || ST_Z(ST_PointN(geom1,i)) || '),';
END LOOP;
newLines := newLines || ')';
newLines := REPLACE(newLines, ',)',')');

RETURN ST_SetSRID(newLines, ST_SRID(geom1));
END \$\$
LANGUAGE plpgsql
STABLE
RETURNS NULL ON NULL INPUT;
``````