WITH 
ret AS (
    SELECT 
        15997 AS gid,    '0102000020BB0B000015000000E17A146E4DFE37413E0AD79367A95241F6285CCF5BFE3741A4703D5A62A95241A4703D0A60FE3741333333735DA952411F85EB5160FE37413E0AD7C358A952411F85EB115FFE374148E17A5453A952417B14AE0755FE3741B81E858B4DA95241713D0AD751FE3741713D0AF748A9524148E17A944CFE37417B14AEA744A95241CDCCCC4C45FE37410000001040A9524152B81E8545FE3741CDCCCC5C3CA952411F85EB914CFE3741000000A037A952419A9999994EFE37413333331330A9524185EB513852FE374115AE47B12AA952413E0AD7E358FE37418FC2F51827A95241CDCCCC0C5FFE3741713D0A1724A952415C8FC2756CFE374115AE47011FA95241D7A370BD6EFE37419A9999091DA95241295C8FC26FFE3741C3F5289C16A95241676666A670FE3741295C8F5212A952415C8FC2F57DFE37418FC2F5280EA9524115AE476189FE37413E0AD7430AA95241'::geometry (LINESTRING, 3003) AS geom 
)
SELECT 
	pointn,
	St_AsText(St_PointN(geom,pointn))
FROM
	ret,
	generate_series(1,St_NumPoints(geom)) AS pointn
;

/*
 pointn |          st_astext
--------+------------------------------
      1 | POINT(1572429.43 4892062.31)
      2 | POINT(1572443.81 4892041.41)
      3 | POINT(1572448.04 4892021.8)
      4 | POINT(1572448.32 4892003.06)
      5 | POINT(1572447.07 4891981.32)
      6 | POINT(1572437.03 4891958.18)
      7 | POINT(1572433.84 4891939.86)
      8 | POINT(1572428.58 4891922.62)
      9 | POINT(1572421.3 4891904.25)
     10 | POINT(1572421.52 4891889.45)
     11 | POINT(1572428.57 4891870.5)
     12 | POINT(1572430.6 4891840.3)
     13 | POINT(1572434.22 4891818.77)
     14 | POINT(1572440.89 4891804.39)
     15 | POINT(1572447.05 4891792.36)
     16 | POINT(1572460.46 4891772.02)
     17 | POINT(1572462.74 4891764.15)
     18 | POINT(1572463.76 4891738.44)
     19 | POINT(1572464.65 4891721.29)
     20 | POINT(1572477.96 4891704.64)
     21 | POINT(1572489.38 4891689.06)
*/

WITH
sp AS (
    SELECT
        1 AS gid,    
		St_StartPoint('0102000020BB0B0000090000001F85EB9152FE37411F85EB812AA952413E0AD7E358FE37418FC2F51827A95241CDCCCC0C5FFE3741713D0A1724A952415C8FC2756CFE374115AE47011FA95241D7A370BD6EFE37419A9999091DA95241295C8FC26FFE3741C3F5289C16A95241676666A670FE3741295C8F5212A952415C8FC2F57DFE37418FC2F5280EA95241E17A142E89FE374152B81E550AA95241'::geometry (LINESTRING, 3003))::geometry (POINT, 3003)  AS geom_sp
),
ret AS (
    SELECT 
        15997 AS gid,    '0102000020BB0B000015000000E17A146E4DFE37413E0AD79367A95241F6285CCF5BFE3741A4703D5A62A95241A4703D0A60FE3741333333735DA952411F85EB5160FE37413E0AD7C358A952411F85EB115FFE374148E17A5453A952417B14AE0755FE3741B81E858B4DA95241713D0AD751FE3741713D0AF748A9524148E17A944CFE37417B14AEA744A95241CDCCCC4C45FE37410000001040A9524152B81E8545FE3741CDCCCC5C3CA952411F85EB914CFE3741000000A037A952419A9999994EFE37413333331330A9524185EB513852FE374115AE47B12AA952413E0AD7E358FE37418FC2F51827A95241CDCCCC0C5FFE3741713D0A1724A952415C8FC2756CFE374115AE47011FA95241D7A370BD6EFE37419A9999091DA95241295C8FC26FFE3741C3F5289C16A95241676666A670FE3741295C8F5212A952415C8FC2F57DFE37418FC2F5280EA9524115AE476189FE37413E0AD7430AA95241'::geometry (LINESTRING, 3003) AS geom 
),
points AS (
SELECT
    St_AddPoint(
        geom,
        geom_sp,
        St_NumPoints(
            ST_LineSubstring(
                geom, 
                0, 
                ST_LineLocatePoint(
                    geom,
                    geom_sp
                )
            )
        ) - 1
    ) AS geom
FROM
    ret,
    sp
)
SELECT 
	pointn,
	St_AsText(St_PointN(geom,pointn))
FROM
	points,
	generate_series(1,St_NumPoints(geom)) AS pointn
;

/*
 pointn |          st_astext
--------+------------------------------
      1 | POINT(1572434.57 4891818.03)
      2 | POINT(1572429.43 4892062.31)
      3 | POINT(1572443.81 4892041.41)
      4 | POINT(1572448.04 4892021.8)
      5 | POINT(1572448.32 4892003.06)
      6 | POINT(1572447.07 4891981.32)
      7 | POINT(1572437.03 4891958.18)
      8 | POINT(1572433.84 4891939.86)
      9 | POINT(1572428.58 4891922.62)
     10 | POINT(1572421.3 4891904.25)
     11 | POINT(1572421.52 4891889.45)
     12 | POINT(1572428.57 4891870.5)
     13 | POINT(1572430.6 4891840.3)
     14 | POINT(1572434.22 4891818.77)
     15 | POINT(1572440.89 4891804.39)
     16 | POINT(1572447.05 4891792.36)
     17 | POINT(1572460.46 4891772.02)
     18 | POINT(1572462.74 4891764.15)
     19 | POINT(1572463.76 4891738.44)
     20 | POINT(1572464.65 4891721.29)
     21 | POINT(1572477.96 4891704.64)
     22 | POINT(1572489.38 4891689.06)
(22 righe)
*/


WITH
sp AS (
    SELECT
        1 AS gid,    
		St_StartPoint('0102000020BB0B0000090000001F85EB9152FE37411F85EB812AA952413E0AD7E358FE37418FC2F51827A95241CDCCCC0C5FFE3741713D0A1724A952415C8FC2756CFE374115AE47011FA95241D7A370BD6EFE37419A9999091DA95241295C8FC26FFE3741C3F5289C16A95241676666A670FE3741295C8F5212A952415C8FC2F57DFE37418FC2F5280EA95241E17A142E89FE374152B81E550AA95241'::geometry (LINESTRING, 3003))::geometry (POINT, 3003)  AS geom_sp
),
ret AS (
    SELECT 
        15997 AS gid,    '0102000020BB0B000015000000E17A146E4DFE37413E0AD79367A95241F6285CCF5BFE3741A4703D5A62A95241A4703D0A60FE3741333333735DA952411F85EB5160FE37413E0AD7C358A952411F85EB115FFE374148E17A5453A952417B14AE0755FE3741B81E858B4DA95241713D0AD751FE3741713D0AF748A9524148E17A944CFE37417B14AEA744A95241CDCCCC4C45FE37410000001040A9524152B81E8545FE3741CDCCCC5C3CA952411F85EB914CFE3741000000A037A952419A9999994EFE37413333331330A9524185EB513852FE374115AE47B12AA952413E0AD7E358FE37418FC2F51827A95241CDCCCC0C5FFE3741713D0A1724A952415C8FC2756CFE374115AE47011FA95241D7A370BD6EFE37419A9999091DA95241295C8FC26FFE3741C3F5289C16A95241676666A670FE3741295C8F5212A952415C8FC2F57DFE37418FC2F5280EA9524115AE476189FE37413E0AD7430AA95241'::geometry (LINESTRING, 3003) AS geom 
),
points AS (
SELECT
    St_AddPoint(
        geom,
        geom_sp,
		13
    ) AS geom
FROM
    ret,
    sp
)
SELECT 
	pointn,
	St_AsText(St_PointN(geom,pointn))
FROM
	points,
	generate_series(1,St_NumPoints(geom)) AS pointn
;

/*
 pointn |          st_astext
--------+------------------------------
      1 | POINT(1572434.57 4891818.03)
      2 | POINT(1572429.43 4892062.31)
      3 | POINT(1572443.81 4892041.41)
      4 | POINT(1572448.04 4892021.8)
      5 | POINT(1572448.32 4892003.06)
      6 | POINT(1572447.07 4891981.32)
      7 | POINT(1572437.03 4891958.18)
      8 | POINT(1572433.84 4891939.86)
      9 | POINT(1572428.58 4891922.62)
     10 | POINT(1572421.3 4891904.25)
     11 | POINT(1572421.52 4891889.45)
     12 | POINT(1572428.57 4891870.5)
     13 | POINT(1572430.6 4891840.3)
     14 | POINT(1572434.22 4891818.77)
     15 | POINT(1572440.89 4891804.39)
     16 | POINT(1572447.05 4891792.36)
     17 | POINT(1572460.46 4891772.02)
     18 | POINT(1572462.74 4891764.15)
     19 | POINT(1572463.76 4891738.44)
     20 | POINT(1572464.65 4891721.29)
     21 | POINT(1572477.96 4891704.64)
     22 | POINT(1572489.38 4891689.06)
(22 righe)
*/