当我运行一个包含::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)