[postgis-users] Restrict values entered in a shapefile in postgis/postgres

Sandro Santilli strk at keybit.net
Thu Apr 19 03:34:00 PDT 2012


On Thu, Apr 19, 2012 at 03:40:48PM +0530, MaheshKrishnan wrote:

> So the problem is I want to restrict the values that can be entered in a
> specific column of a specific shape file but haven't been able to do it.

You mean ".. of a specific table", not "shape file".

> For example if there is a shapefile called Hydro_points and it has an
> attribute column call Hydro_type I want only the values 1, 2 or 3 to be
> entered here.
...
> That table should not accept any other values

You can use CHECK constraints on the table, with something like:

 ALTER TABLE mytable ADD CONSTRAINT only_one_two_three
   CHECK "Hydro_type" IN (1,2,3);

(check the PostgreSQL reference manual to tweak and lear more)

--strk;

  ,------o-. 
  |   __/  |    Delivering high quality PostGIS 2.0 !
  |  / 2.0 |    http://strk.keybit.net - http://vizzuality.com
  `-o------'




More information about the postgis-users mailing list