1

I want to merge some lines with conditions but nothing seems to done . Here is the query :

drop table if exists touches_diameter_material;
create table touches_diameter_material as select a.*,st_union(a.geom,b.geom) 
as fusion from pipe a, pipe b where a.id > b.id and  a.material = b.material 
and a.diameter = b.diameter   and st_touches(a.geom,b.geom)

if you know how to do it I'll be pleased to get some help.

  • what conditions exactly? and "nothing seems to done"? what are you referring to? – ziggy Sep 28 '17 at 15:25
  • Nomraly when I execute st_union the number of lines of the resulting table shoud be less than the one before union yet I still have the same number of records you see what I mean. Like the union wasn't executed or he didn't take in consideration the where clauses I put – zakaria mouqcit Sep 28 '17 at 15:32
  • 1
    im surprised the query doesnt throw an error that you are not using a group by with the st_union function – ziggy Sep 28 '17 at 15:41
1

With ST_Union, you need a GROUP BY statement, otherwise everything will be combined and you will receive a single record only.

SELECT
    a.id,
    a.material,
    a.diameter,
    st_union(a.geom,b.geom) as fusion
FROM pipe a, pipe b
WHERE a.id > b.id
AND  a.material = b.material 
AND a.diameter = b.diameter
AND st_touches(a.geom,b.geom)
GROUP by a.id, a.material, a.diameter
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.