Creating spatial tables with PostGIS

No, they are not producing the same results.

With the second method you would still need to add a record in the GEOMETRY_COLUMNS table, and you would need to do it with an INSERT statement, or using the Populate_Geometry_Columns function as suggested in the other answer.

AddGeometryColumn will take care of doing this for you (together with creating the index and the constraints).


In PostGIS 2.0+ you can create the geometry column directly using common data definition language.

For example:

-- points in geographic wgs84 coordinates (epsg:4326)
create table mypoints (id serial, name varchar, geom geometry(Point, 4326));

-- lines in spherical mercator (epsg:3857)
create table mylines (id serial, name varchar, geom geometry(LineString, 3857));

-- polygons in Dutch national coordinate system (epsg:28992)
create table mypolygons (id serial, name varchar, geom geometry(Polygon, 28992));

-- multipolygons in British National Grid (epsg:27700)
create table 
  mymultipolygons(id serial, name varchar, geom geometry(Multipolygon, 27700));

-- generic geometry (no data type constraints)
create table mygeometries(id serial, name varchar, geom geometry);

The two methods should produce the same results. AddGeometryColumn will not only create the geometry field, it will validate and create necessary indexes too. As long as you do all these things manually, the result will be the same. If you have an existing geometry column, you could use the Populate_Geometry_Columns function to validate it and create the necessary indexes.