Name

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

Synopsis

text AddGeometryColumn(varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

text AddGeometryColumn(varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

text AddGeometryColumn(varchar catalog_name, varchar schema_name, varchar table_name, varchar column_name, integer srid, varchar type, integer dimension);

Description

Adds a geometry column to an existing table of attributes. The schema_name is the name of the table schema (unused for pre-schema PostgreSQL installations). The srid must be an integer value reference to an entry in the SPATIAL_REF_SYS table. The type must be an uppercase string corresponding to the geometry type, eg, 'POLYGON' or 'MULTILINESTRING'. An error is thrown if the schemaname doesn't exist (or not visible in the current search_path) or the specified SRID, geometry type, or dimension is invalid.

[Note]

Views and derivatively created spatial tables will need to be registered in geometry_columns manually, since AddGeometryColumn also adds a spatial column which is not needed when you already have a spatial column. Refer to Section 4.2.4, “Manually Registering Geometry Columns in geometry_columns”.

This method implements the OpenGIS Simple Features Implementation Specification for SQL.

This function supports 3d and will not drop the z-index.

This method supports Circular Strings and Curves

Examples

-- Create a new simple PostgreSQL table
postgis=# CREATE TABLE my_schema.my_spatial_table (id serial);

-- Describing the table shows a simple table with a single "id" column.
postgis=# \d my_schema.my_spatial_table
							 Table "my_schema.my_spatial_table"
 Column |  Type   |                                Modifiers
--------+---------+-------------------------------------------------------------------------
 id     | integer | not null default nextval('my_schema.my_spatial_table_id_seq'::regclass)

-- Add a spatial column to the table
postgis=# SELECT AddGeometryColumn ('my_schema','my_spatial_table','the_geom',4326,'POINT',2);

--Add a curvepolygon
SELECT AddGeometryColumn ('my_schema','my_spatial_table','the_geomcp',4326,'CURVEPOLYGON',2);

-- Describe the table again reveals the addition of a new "the_geom" column.
postgis=# \d my_schema.my_spatial_table
   Column   |   Type   |                                Modifiers

------------+----------+-------------------------------------------------------------------------
 id         | integer  | not null default nextval('my_schema.my_spatial_table_id_seq'::regclass)
 the_geom   | geometry |
 the_geomcp | geometry |
Check constraints:
	"enforce_dims_the_geom" CHECK (ndims(the_geom) = 2)
	"enforce_dims_the_geomcp" CHECK (ndims(the_geomcp) = 2)
	"enforce_geotype_the_geom" CHECK (geometrytype(the_geom) = 'POINT'::text OR
the_geom IS NULL)
	"enforce_geotype_the_geomcp" CHECK (geometrytype(the_geomcp) = 'CURVEPOLYGON
'::text OR the_geomcp IS NULL)
	"enforce_srid_the_geom" CHECK (srid(the_geom) = 4326)
	"enforce_srid_the_geomcp" CHECK (srid(the_geomcp) = 4326)

See Also

DropGeometryColumn, DropGeometryTable, Section 4.2.4, “Manually Registering Geometry Columns in geometry_columns”