当我运行包含::geometry
转换的PostgreSQL查询时,出现type "geometry" does not exist
错误。我在Ubuntu 12.04上使用php5-pgsql V5.3.10,php5-fpm 5.4.13,Laravel 4,Postgresql 9.1,PostGIS 2.0.1。 geometry
类型是PostGIS特定的。使用PHP时PostgreSQL查询错误
没有投射,查询运行良好。当使用pgAdmin3直接查询PostgreSQL数据库时,原始查询也可以正常工作。为什么是这样?
查询
$busstops = DB::connection('pgsql')
->table('locations')
->select(DB::raw('geog::geometry as lat, geog::geometry as lng'))
->get();
查询而无需进行转换(没有错误)
$busstops = DB::connection('pgsql')
->table('locations')
->select(DB::raw('geog as lat, geog as lng'))
->get();
错误:
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几何
List of data types
Schema | Name | Description
--------+----------+-----------------------------------------
public | geometry | postgis type: Planar spatial data type.
(1 row)
你安装了'geometry'型成一个单独的模式这是对'search_path'中的任何机会手动查询,但不是通过你的工具?或者你不是真的在你的工具和手动查询中连接到同一个数据库? –
@CraigRinger我跑了'CREATE EXTENSION postgis; CREATE EXTENSION postgis-topology;'连接到数据库时,我认为(不正确?)它会为所有模式安装'geometry'类型?我确实有多个模式,如何为specfic/all模式安装'geometry'类型? – Nyxynyx
您不必为每个模式安装类型。您可以选择在自己的模式中安装扩展,在这种情况下,该模式必须位于search_path中,以使扩展可用。你似乎没有这样做,所以我怀疑这是一个search_path问题。在'psql'中用'\ dT geometry'确认,确认'geometry'类型被列为其中的模式。如果它被安装在'public'中,那么可能你的'search_path'被设置,以便它不包含您的应用使用“公共”模式吗? –