When I run a PostgreSQL query containing ::geometry casting, I get a type "geometry" does not exist error. I am using php5-pgsql V5.3.10, php5-fpm 5.4.13, Laravel 4, Postgresql 9.1, PostGIS 2.0.1 on Ubuntu 12.04. geometry type is PostGIS-specific.
Without the casting, the query runs fine. The original query also works fine when queried directly against the PostgreSQL database using pgAdmin3. Why is this?
Query
$busstops = DB::connection('pgsql')
->table('locations')
->select(DB::raw('geog::geometry as lat, geog::geometry as lng'))
->get();
Query without casting (No errors)
$busstops = DB::connection('pgsql')
->table('locations')
->select(DB::raw('geog as lat, geog as lng'))
->get();
Error:
Exception: SQLSTATE[42704]: Undefined object: 7 ERROR: type "geometry" does not exist
LINE 1: select geog::geometry as lat from "locations"
^ (SQL: select geog::geometry as lat from "locations") (Bindings: array (
))
\dT geometry
List of data types
Schema | Name | Description
--------+----------+-----------------------------------------
public | geometry | postgis type: Planar spatial data type.
(1 row)
The application is switching the search_path around so that public isn't on the search_path. By default extensions are installed into public, so you're finding that geometry and the other PostGIS types and functions become unavailable from the application when it switches the search_path.
You need to:
Create a new schema postgis;
Move the PostGIS extension into the postgis schema; and
Make sure that the new postgis schema is always on the search_path, probably using application-specific settings
Related
I am getting an error while loading Raster data to a postgres table
ERROR: function st_bandmetadata(public.raster, integer[]) does not exist
LINE 1: SELECT array_agg(pixeltype)::text[] FROM st_bandmetadata($1...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
QUERY: SELECT array_agg(pixeltype)::text[] FROM st_bandmetadata($1, ARRAY[]::int[]);
CONTEXT: SQL function "_raster_constraint_pixel_types" during inlining
COPY elevation_hi, line 1: "1 01000001006A98816335DA4E3F6A98816335DA4EBFA2221ECF131C64C0FEE6DF13C4963640000000000000000000000000..."
3139
Any idea on this?
I have below extensions present in the database where I am trying to create the table:
CREATE EXTENSION postgis
CREATE EXTENSION postgis_topology
CREATE EXTENSION fuzzystrmatch
Please help me on this If you have any idea.
My search path set for the database is ::
search_path
----------------------------------------------
"$user", public, rasters, postgis, pg_catalog
post_GIS version
SELECT postgis_version();
postgis_version
---------------------------------------
2.1 USE_GEOS=1 USE_PROJ=1 USE_STATS=1
Please let me knwo if you havve face this issue earlier.
I'm trying to use ST_SnapToGrid(geometry geomA, float size); on PostGIS 2.5.2 but I keep getting the following error:
ERROR: function public.st_snaptogrid(geometry, integer, integer, double precision, double precision) does not exist
LINE 1: SELECT public.ST_SnapToGrid($1, 0, 0, $2, $3)
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
The same happens with the examples in the documentation, the first example runs fine but the second one returns the same error:
SELECT ST_SnapToGrid(
ST_GeomFromEWKT('LINESTRING(-1.1115678 2.123 2.3456 1.11111,4.111111 3.2374897 3.1234 1.1111, -1.11111112 2.123 2.3456 1.1111112)'),
ST_GeomFromEWKT('POINT(1.12 2.22 3.2 4.4444)'),
0.1, 0.1, 0.1, 0.01);
SELECT ST_SnapToGrid(
ST_GeomFromText('LINESTRING(1.1115678 2.123, 4.111111 3.2374897, 4.11112 3.23748667)'),
0.001);
Update
I'm using the mdillon/postgis Docker image and move PostGIS like this:
CREATE SCHEMA abc;
ALTER SCHEMA abc OWNER TO abc;
UPDATE pg_extension SET extrelocatable = TRUE WHERE extname = 'postgis';
ALTER EXTENSION postgis set schema abc;
I guess that the extension (and, as a consequence, the function) is installed in a schema different from public.
In psql, run \dx postgis to see in which schema PostGIS is installed.
You cannot change an extension's schema by modifying the catalog. Doing that will break your database.
I need to insert a point into table of type postgres, I tried:
\DB::statement("SET search_path = postgis, public;");
\DB::statement("INSERT INTO points (latlong) VALUES( ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));");
but I got error:
SQLSTATE[42883]: Undefined function: 7 ERROR: function st_geomfromtext(unknown, integer) does not exist
LINE 1: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts. (SQL: INSERT INTO points (latlong) VALUES(ST_GeomFromText('POINT(-71.060316 48.432044)', 4326));)
I am using postgres 9.4.5 with postgis installed .. any idea?
Install PostGIS using something like CREATE EXTENSION IF NOT EXISTS postgis
Creating a geometry by formatting a WKT string for ST_GeomFromText is not the best way to make a geometry (slower, lossy, error prone, etc.), unless your source data is already text. To make a point geometry from two floating point values, use something like:
DB::insert('INSERT INTO points (latlong) VALUES(ST_SetSRID(ST_MakePoint(?, ?), 4326))',
[lng, lat]);
i am using postgresql version :
"PostgreSQL 9.3.1 on x86_64-unknown-linux-gnu, compiled by gcc (GCC) 4.6.3 20120306 (Red Hat 4.6.3-2), 64-bit"
i have created 2 tables A and B with point and polygon as a data type.
now i want to know whether point is inside the polygon or not.
for this i am trying to use ST_Intersect(A.point_LatLong , B.polygon_abc);
my query is :
SELECT A.id
FROM A, B
WHERE A.name = 'callifornia'
AND ST_Intersect(A.point_LatLong , B.polygon_abc);
here point_latLong and polygon_abc are column name having datatype point and polygon in table A and B.
but this query gives an error :
ERROR: function st_intersect(point, polygon) does not exist
LINE 3: WHERE city.city_name = 'callifornia' AND ST_intersect(city.c...
HINT: No function matches the given name and argument types. You might need to add
explicit type casts.
How can I solve this problem? I even not be able to use any other spatial method in postgresql like st_contains() etc let me know if you have any solution.
You are trying to mix PostgreSQL's built-in (limited, but useful) geometric types with PostGIS functions. It sounds like you didn't install PostGIS, either. You've also typo'd the function name, it's ST_Intersects not ST_Intersect.
First, if you want to use PostGIS, make sure it's installed and then:
CREATE EXTENSION postgis;
Next, you'll probably find that you can't actually call ST_Intersects with a point and a polygon. PostGIS works with its own geometry type. It has some converters for the PostgreSQL internal types, but they're only limited. So calling PostGIS functions with primitive geometric types can result in errors like:
postgres=# SELECT ST_Intersects( polygon( box(point(0,0), point(10,10)) ), point(5,5) );
ERROR: function st_intersects(polygon, point) does not exist
LINE 1: SELECT ST_Intersects( polygon( box(point(0,0), point(10,10))...
^
HINT: No function matches the given name and argument types. You might need to add explicit type casts.
You'll often have to convert them to PostGIS's own geometry type. PostGIS provides some explicit casts for this for most types, e.g.:
postgres=# SELECT ST_Intersects(
polygon( box(point(0,0), point(10,10)) )::geometry,
point(5,5)::geometry
);
st_intersects
---------------
t
(1 row)
So in your query, that'd be:
ST_Intersects(A.point_LatLong::geometry , B.polygon_abc::geometry);
I have a function in postgres that inserts data to a table, and one of the columns is of type point.
I don't know how to save my gotten data to an acceptable form for the function to save my data.
The problematic code in question is :
CREATE OR REPLACE FUNCTION db."setMessage"(eml text, msg text, lat text, lng text)
...
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
ST_SetSRID(ST_MakePoint($3::float, $4::float), 4326)
);
The error received when i call the function is:
ERROR: function st_makepoint(double precision, double precision) does not exist
SQL state: 42883
Hint: No function matches the given name and argument types. You might need to add explicit type casts.
Context: PL/pgSQL function "setMessage" line 9 at SQL statement
I have tries to save the point in string format ('POINT(12.22343 64.22233)'), tried not casting the st_makepoint arguments, and inserting without the outer function (ST_SetSRID).
could anyone tell me what I'm doing wrong?
SOLUTION:
So the method of success was following this link to get the needed libraries. after that i created the required extensions, and now i have access to the desired functions.
To install PostGIS, follow the instructions for your operating system at https://postgis.net/install.
Then, to enable it on your db you can do CREATE EXTENSION postgis; from psql or PGAdmin.
I had a similar problem, that postgres didn't find the function st_makepoint even though postgis extension was installed and I used the correct types for arguments. It turned out that the search path did not contain postgis.
Solution was: alter database my_db set search_path = my_schema, public, postgis;
Hope it helps somebody.
I tried to re-install postgis extension and have tried many soluations but did not work for me.
I just edit my query and put extensions keyword before functions name like this:
INSERT INTO
db.messages
VALUES
(DEFAULT,
id,
$2,
DEFAULT,
extensions.ST_SetSRID(extensions.ST_MakePoint($3::float, $4::float), 4326)
);
That worked for me.