Monday 19 June 2017

postgresql - Creating or adding geometry colunm fails even with postgis enabled


I'm trying to add a geometry colunm to a table in a database with postgis extention enabled (other tables in this schema even have geometry colunms), but it fails:


ALTER TABLE my_schema.my_table ADD COLUMN geom geometry(MultiPolygon, 4326);

gets me an error:


ERROR:  type "geometry" does not exist

although


CREATE EXTENSION postgis;


returns


ERROR:  extension "postgis" already exists

I'm running Postgres 9.5, but I cannot tell postgis verion because it throws another error


ERROR:  function postgis_full_version() does not exist

Although postgis is listed under extensions in pgadmin.



Answer



The PostGIS extension must be installed in a schema that must also be in the user search path.



You can check where it is installed with the command


select e.extname,n.* 
from pg_extension e, pg_namespace n
where e.extnamespace = n.oid and e.extname='postgis';

And you can check if the schema where it is installed is in the user search path by issuing


show search_path;

If not, you can permanently add the path by altering the user.


ALTER USER username SET search_path TO "$user", public, postgis_schema;


As the previous command takes effect at the next login only, you can apply it immediately by applying


SET search_path TO "$user", public, postgis_schema;

No comments:

Post a Comment

arcpy - Changing output name when exporting data driven pages to JPG?

Is there a way to save the output JPG, changing the output file name to the page name, instead of page number? I mean changing the script fo...