2

I'm trying to save the bounding box of a multipolygon into a polygon column like this:

UPDATE "mytbl" SET bb = ST_SetSRID(ST_Envelope(mp::geometry),4326) WHERE "mytbl"."id" = 1

But I receive the error:

PG::InvalidParameterValue: ERROR: Geometry type (MultiPolygon) does not match column type (Polygon)

I also tried to use the ST_ConvexHull function but it gave me the same error.

6
  • You don't want to convert your polygon geometry column to multipolygon in order to solve the problem? – Vincent Bré Dec 12 '19 at 13:19
  • 1
    I don't understand how it is possible to get a multipolygon from ST_Envelope postgis.net/docs/ST_Envelope.html. – user30184 Dec 12 '19 at 13:27
  • I also don't understand how this is possible... When playing around in the postgres console it only happens when mp is NULL. but from my app it always gives the error even on valid single ring multipolygons – complistic Dec 12 '19 at 13:39
  • Could there be two issues here, some kind of race condition where mp is still saving, so mp is null and ST_Envelope just returns the input if it is null? – complistic Dec 12 '19 at 13:41
  • 1
    Create bb column without geometry type constraint as generic "geometry" so you can at least see what gets inserted. – user30184 Dec 12 '19 at 14:06
1

As far as I know, you have two possible solutions.

  1. add a column of the type multipolygon.
  2. Dump your result (this solution will return more than one row and you have to save an array of geometry in bb)

Therefore, I suggest to add a bb2 column (AddGeometryColumn) with the type multipolygon:

SELECT AddGeometryColumn('public', 
'mytbl', 'bb2', 4326,'MULTIPOLYGON', 2);

Then, run your own code. It should work.

UPDATE "mytbl" SET bb2 = 
ST_SetSRID(ST_Envelope(mp::geometry),4326) WHERE 
"mytbl"."id" = 1

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.