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)
geometry
type into a separate schema that's on thesearch_path
in manual queries but not via your tool? Or that you're not really connecting to the same DB in your tool and manual queries? – Craig Ringer Apr 3 '13 at 7:23CREATE EXTENSION postgis; CREATE EXTENSION postgis-topology;
when connected to the database, which I assumed (incorrectly?) that it will installgeometry
type for all schemas? I do have multiple schemas, how do I installgeometry
type for a specfic/all schemas? – Nyxynyx Apr 3 '13 at 7:26search_path
for 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 geometry
inpsql
, confirm what schema thegeometry
type is listed as being in. If it's installed inpublic
then perhaps yoursearch_path
is being set so that it doesn't include thepublic
schema by your app? – Craig Ringer Apr 3 '13 at 7:34public
schema!! – Nyxynyx Apr 3 '13 at 7:38public
schema 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 theSCHEMA
clause ofCREATE EXTENSION
: postgresql.org/docs/current/static/sql-createextension.html – Craig Ringer Apr 3 '13 at 7:40