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)
geometrytype into a separate schema that's on thesearch_pathin manual queries but not via your tool? Or that you're not really connecting to the same DB in your tool and manual queries?CREATE EXTENSION postgis; CREATE EXTENSION postgis-topology;when connected to the database, which I assumed (incorrectly?) that it will installgeometrytype for all schemas? I do have multiple schemas, how do I installgeometrytype for a specfic/all schemas?search_pathfor the extension to be usable. You don't seem to have done that so I doubt this is a search_path issue. Confirm with\dT geometryinpsql, confirm what schema thegeometrytype is listed as being in. If it's installed inpublicthen perhaps yoursearch_pathis being set so that it doesn't include thepublicschema by your app?publicschema!!publicschema is always on thesearch_path, or install it do a different schema that contains nothing but PostGIS (called, say,postgis) and make sure that's always on thesearch_path. See theSCHEMAclause ofCREATE EXTENSION: postgresql.org/docs/current/static/sql-createextension.html