Prabesh Shrestha
Prabesh Shrestha

Reputation: 2742

how to use geometry datatype to postgres table?

I have setup a postgres database(version 9.1) and trying to create a table capable of storing st_geometry with the following query :

CREATE TABLE sensitive_areas (area_id integer, name varchar(128), zone st_geometry);

But I am getting the error as follows :

ERROR:  type "st_geometry" does not exist

Do I need to configure my postgres installation further to enable geometry data type .

Upvotes: 5

Views: 9023

Answers (2)

Mike T
Mike T

Reputation: 43622

The correct type name is geometry. If you are you are using PostGIS 2.0 you can use a typmod:

-- If you haven't done so already
CREATE EXTENSION postgis;

-- Make a table of Polygons, using long/lat coords
CREATE TABLE sensitive_areas (
    area_id integer primary key,
    name varchar(128),
    zone geometry(Polygon,4326)
);

Upvotes: 11

Quassnoi
Quassnoi

Reputation: 425271

CREATE TABLE sensitive_areas (area_id integer, name varchar(128), zone geometry);

You should have PostGIS installed in you db for this to work.

Upvotes: 4

Related Questions