2

当我运行一个包含::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 特定的。

没有强制转换,查询运行良好。当使用 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)
4

1 回答 1

2

该应用程序正在切换,search_path因此public不在search_path. 默认情况下public,扩展安装geometrysearch_path.

你需要:

  • 创建一个新模式postgis
  • 将 PostGIS 扩展移动到postgis架构中;和
  • 确保新postgis架构始终在 上search_path,可能使用特定于应用程序的设置
于 2013-04-03T08:10:58.007 回答