4

I am attempting to combine the geometries for multiple records using the following:

INSERT INTO schema.boundary (name, geom)  
SELECT 'Name' ,  ST_Union(geom) FROM schema.boundary WHERE id = 0;

This returns the error:

ERROR:  Geometry type (Polygon) does not match column type (MultiPolygon)
********** Error **********

So I then tried the following:

INSERT INTO schema.boundary (name, geom)  
SELECT 'Name' ,  ST_Union(ST_Multi(geom)) FROM schema.boundary WHERE id = 0;

This returns the same error.

I managed to combine all of the target geometry fields except for one.

Checking the geometry type using ST_GeometryType(geom) for the all records returns 'ST MultiPolygon'.

I've also tried updating the single record using ST_Multi(geom) and then attempting the above queries to no avail.

Why am I getting this error if type is 'MultiPolygon' ?

Is there another PostGIS function I can use to combine incompatible geometry types?

4

My guess is that the union-ed polygon is a single part polygon and not a multipart polygon, hence failing on the insert, not on the union.

Could you try something like:

INSERT INTO schema.boundary (name, geom)  
SELECT 'Name' ,  ST_Multi(ST_Union(ST_Multi(geom))) FROM schema.boundary WHERE id = 0;

If that doesn't work, could you post the schema and some sample data that you've used to re-create the problem?

  • 2
    You were correct it was failing to insert for that reason. St_Multi(ST_Union(geom)) actually worked as well. Thanks. – Don P Jun 30 '17 at 19:40

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.