4

I want to union the geometry of waterlines grouped by a table column in a new view. My problem is that I apparently needes to specify the geometry type using CAST function. But I cannot figure how to use the CAST function in combination with ST_UNION.

CREATE OR REPLACE VIEW _06_spildevand_vandloeb.drikkevandsledning_dissolve as
 SELECT row_number() over () as id, 
 ST_UNION(the_geom)::geometry(MULTILINESTRING,25832), 
 descr 
 FROM _06_spildevand_vandloeb.ledninger_vand
 GROUP BY descr

This results in, though, that the name of geometry column is called ST_UNION, so I must have got the syntax wrong when using CAST and ST_UNION.

What is the problem?

PolyGeo
65.5k29 gold badges115 silver badges350 bronze badges
asked Jan 13, 2020 at 15:11
1
  • I think casting is not really relevant. just : "St_Union(geom) as geom" should do the trick, the result will be cast in the simplest geometry possible, so multilinestring or linestring. However, you can still enforce it and use ::geometry(MULTILINESTRING, 25832) Commented Jan 13, 2020 at 15:25

1 Answer 1

6

You need to alias your columns, effectively giving it a name, if they are the result of a function, or PostgreSQL will use the function name of the outermost function it uses to generate the column (values)!

CREATE OR REPLACE VIEW _06_spildevand_vandloeb.drikkevandsledning_dissolve AS
 SELECT ROW_NUMBER() OVER() AS id, 
 ST_Union(the_geom)::GEOMETRY(MULTILINESTRING,25832) AS geom, -- alias AS geom
 descr 
 FROM _06_spildevand_vandloeb.ledninger_vand
 GROUP BY
 descr
;
answered Jan 13, 2020 at 15:22

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.