4

Storing MultiPolygon and Polygon features in a single column used to be as simple as not creating or removing the geometry type check constraint.

Is there a similar simple fix in PostGIS 2?

5

Say you have my_table with a geom column with a typmod geometry(Polygon,4326):

CREATE table my_table(
  gid serial primary key,
  geom geometry(Polygon,4326)
);

To store whatever geometry type you want, just redefine the typmod to geometry(Geometry,4326), or don't use typmods. (The former enforces the SRID, and the later doesn't enforce anything):

ALTER TABLE my_table ALTER COLUMN geom TYPE geometry(Geometry,4326);

INSERT INTO my_table(geom)
VALUES
  ('SRID=4326;POLYGON EMPTY'),
  ('SRID=4326;MULTIPOLYGON EMPTY');

However, the data in the geometry_columns view might not work with some applications, since it also says 'GEOMETRY'.

Lastly, CHECK CONSTRAINTS can always be used with any table, as was the norm in PostGIS 1.5 and before. If you want to keep the table definitions as they were in 1.5, this is still supported.

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.