PostGIS Change Geometry Type – How to Change Geometry Type to Polygon in PostGIS

postgis

I have a table that has its geometry type as geometry and I need to convert it to Polygon for ogr2ogr to read it. Can't figure this out.

I have tried

ALTER TABLE oak_all_buffers ALTER COLUMN geom type geometry(MultiPolygon, 102689);

error 

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

    ERROR: Geometry type (MultiPolygon) does not match column type (Polygon)
    SQL state: 22023

and

ALTER TABLE oak_all_buffers ALTER COLUMN geom type geometry(Polygon, 102689);

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

ERROR: Geometry type (Polygon) does not match column type (MultiPolygon)
SQL state: 22023

enter image description here

Best Answer

You can change the Column Type to Polygon with this command:

ALTER TABLE oak_all_buffers ALTER COLUMN geom type geometry(Polygon, 102689);

or change to MultiPolygon if you have mixed Polygon/Multipolygon (credits @Vesanto)

ALTER TABLE oak_all_buffers ALTER COLUMN geom type geometry(MultiPolygon, 102689) using ST_Multi(geom);