PostgreSQL PostGIS – Copying Schema with Geometry Column

pg-dumppostgispostgresqlschema-copy

According to the PostGIS manual, geometry columns should not by added directly, but using AddGeometryColumn():

AddGeometryColumn — Adds a geometry column to an existing table of
attributes.

I am copying a schema from one PostgreSQL instance to another. I wonder if the SQL created by pg_dump is good enough – will it create the geometry columns the same way AddGeometryColumn() does?

Best Answer

Adam,

First that is old document -- new one is here: http://postgis.net/docs/AddGeometryColumn.html

Though what they say in both is the same.

The using that function is only need for 1.5 and below. 2.0 we encourage you to just create the table normally.

something like

CREATE TABLE test(gid serial primary key, geom geometry(POLYGON, 4326) );

pg_dump works fine either way since in old version it would restore the constraints and new version the create table would be built with typmodifiers.