Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

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?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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