4

I installed Postgres 9.5. Then I installed PostGIS. Then I created database named geodb. In it I created column with type polygon and several others like id.

Table polygon was created successfully, so it's seems that PostgreSQL know about geometry.

But when I am trying to run next query:

INSERT INTO public.rasters_previews( id, "Path", "Coordinates", "Name", "imageBounds") VALUES (1, 'foo', ST_GeomFromText('polygon((60.536 27.589,60.509 39.054,54.908 38.183,54.93 28.368,60.536 27.589))'), 'xname', 'xbound');

I am getting error that function ST_GeomFromText does not exists.

I tried to do same with setting postgis_22_sample as template but got same result.

What I am doing wrong? Should I do any other manipulation to get DB wotk as geospatial?

3
  • 1
    Does this work: SELECT ST_GeomFromText('polygon((60.536 27.589,60.509 39.054,54.908 38.183,54.93 28.368,60.536 27.589))');
    – kttii
    Commented Aug 9, 2016 at 16:34
  • 3
    Datatype "polygon" is a native PostgreSQL datatype. With PostGIS you want to use "geometry", perhaps with constraint to contain only polygons.
    – user30184
    Commented Aug 9, 2016 at 16:42
  • 1
    did you create the postgis extension in your database? You can do this by running: create extension postgis; Commented Aug 10, 2016 at 7:36

2 Answers 2

7

Is the schema PostGIS was installed into in your search path? The easiest way to test is by running the command:

SELECT PostGIS_Full_Version();

If that returns information on PostGIS you're good to go, if not find the schema you installed PostGIS into and add it to the search path. I usually install PostGIS to its own schema with:

CREATE SCHEMA postgis;
CREATE EXTENSION postgis WITH SCHEMA postgis;
ALTER DATABASE geodb SET search_path TO public, postgis;

Don't forget to add any other schemas in your database to the search path. If you install the topology extension it will create it's own topology schema that will need to go into the search path as well.

2
  • 1
    How to find schema where PostGIS was installed? Commented May 26, 2019 at 12:32
  • 2
    SELECT specific_schema FROM information_schema.routines WHERE routine_name = 'postgis_full_version'; Running this query in the database you're trying to find postgis will tell you which schema postgis was installed into. If PostGIS isn't working then add the schema to that database's search path. Commented May 28, 2019 at 14:51
0

You can re-install your extensions in the public schema if you accidentally installed them in a schema outside of the default search path

for example:


DROP EXTENSION IF exists postgis;
CREATE EXTENSION postgis WITH SCHEMA public;

DROP EXTENSION IF exists "uuid-ossp";
CREATE EXTENSION "uuid-ossp" WITH SCHEMA public;

DROP EXTENSION IF exists unaccent;
CREATE EXTENSION unaccent WITH SCHEMA public;

DROP EXTENSION IF exists cube;
CREATE EXTENSION cube WITH SCHEMA public;

DROP EXTENSION IF exists ltree;
CREATE EXTENSION ltree WITH SCHEMA public;

DROP EXTENSION IF exists tablefunc;
CREATE EXTENSION tablefunc WITH SCHEMA public;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.