Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 .

like image 625
Prabesh Shrestha Avatar asked May 18 '12 08:05

Prabesh Shrestha


1 Answers

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)
);
like image 194
Mike T Avatar answered Nov 15 '22 12:11

Mike T