So, let's summarize for one piece of geodata.
1) Input data are axial lines of roads of one Amsterdam tablet;
2) The length of red lines is not uniform, it is present either on one side or on two sides of quarters and in some places has the bent form;
3) Distances between the red lines and the green lines are different;
4) When trimming lines at intersections, it is possible to lose short green lines (not perpendicular) during filtering.
Conclusion:
1) The script works correctly only for special cases, if it is set correctly;
2) You can remove perpendicular artifacts automatically, only using green lines or a smaller buffer border;
3) It is reasonable to simply trim the green lines by setting the correct trim buffer.
I would specify whether bent parts of red lines can be removed by shortening it to straight parts,
to connect the lines at the breakup points, as small breakups in the lines are not clear, etc.,
In general, you're in the field of geotechnical processing...
try to go that way:
create table blue_lines AS
WITH
tbla AS (SELECT DISTINCT ST_Buffer(geom, 20, 'endcap=flat join=round') geom FROM red_lines)
(SELECT DISTINCT ST_Intersection(a.geom, b.geom) geom FROM green_lines a JOIN tbla b ON ST_Intersects(a.geom, b.geom))
or
create table blue_lines AS
WITH
tbla AS (SELECT DISTINCT ST_Buffer(geom, 15, 'side=right') geom FROM red_lines),
tblb AS (SELECT DISTINCT ST_Intersection(a.geom, b.geom) geom FROM green_lines a JOIN tbla b ON ST_Intersects(a.geom, b.geom)),
tblc AS (SELECT DISTINCT ST_Buffer(geom, 15, 'side=left join=mitre') geom FROM red_lines),
tbld AS (SELECT DISTINCT ST_Intersection(a.geom, b.geom) geom FROM green_lines a JOIN tbla b ON ST_Intersects(a.geom, b.geom))
SELECT * FROM tblb UNION SELECT * FROM tbld
make sure you set this script correctly for the actual road width...
You have a complicated case, and a universal script will be a bit difficult to write, it's easier to solve the problem selectively, based on the specific situation, selecting objects by their id and then combine the results of processing (but it's a long process), you can connect filtering by length, for example, ST_Length(geom)>10, but then it's possible to lose short fragments at intersections, somehow so...