Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgis -ERROR for "enforce_geotype_the_geom"

I have one table named sta.I wanted to add one more column to it .I did so using following statement:

SELECT AddGeometryColumn ('public','station','the_geom',4326,'POINT',2);

the_geom column got added along with following contraints:

CONSTRAINT enforce_dims_the_geom CHECK (st_ndims(the_geom) = 2),
CONSTRAINT enforce_geotype_the_geom CHECK (geometrytype(the_geom) = 'POINT'::text OR the_geom IS NULL),
CONSTRAINT enforce_srid_the_geom CHECK (st_srid(the_geom) = 4326)

I wanted to insert values into the_geom column.I tried:

update station set the_geom = ST_GeomFromEWKT('SRID=4326;POINT(65.6471666666667  25.0368333333333)');

But i am getting error:

ERROR:  new row for relation "station" violates check constraint "enforce_geotype_the_geom"

What does this constraint mean?How to insert values into the same??

like image 944
poonam Avatar asked Dec 03 '25 16:12

poonam


1 Answers

You dont need the constraint to check the dimensions, geotype and its SRID. The typmod of postgis/postgres already do it for you.

The function AddGeometryColumn force the use of typmod (because use_typmod argument is default true, as can you see in addgeometrycolumn documentation.

And, I recommend use the ALTER TABLE statement for add a geometry column into the table

ALTER TABLE station ADD COLUMN the_geom geometry(Point,4326);

And you dont need care for the checks (SRID, geometry type).

like image 61
Anderson Carniel Avatar answered Dec 06 '25 08:12

Anderson Carniel



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!