2

我有 postgreSQL 8.4+PostGIS 1.5。

我想生成 GeoJson。我愿意:

SELECT row_to_json(fc)
 FROM ( SELECT 'FeatureCollection' As type, array_to_json(array_agg(f)) As features
 FROM (SELECT 'Feature' As type
, ST_AsGeoJSON(lg.the_geom)::json As geometry
, row_to_json(lp) As properties
   FROM parcels_temp As lg 
     INNER JOIN (SELECT num, cadastr FROM parcels_temp) As lp 
   ON lg.num = lp.num  ) As f )  As fc;

但是得到一个错误:

 ERROR:  type "json" does not exist
 LINE 4:     , ST_AsGeoJSON(lg.the_geom)::json As geometry

我究竟做错了什么?

4

1 回答 1

10

PostgreSQL 8.4中没有json数据类型。该类型是在 9.2 中引入的,尽管创建了到 9.1 的反向移植;看到这个 bitbucket

使用text. json无论如何,它只是text类型的验证包装器,有趣的是类似的功能row_to_json- 这些功能在 8.4 中也不可用。

如果你不能使用text——比如说,因为你正在使用期望的 3rd 方代码json,或者因为你需要 json 函数——那么是时候升级 PostgreSQL 了。无论如何,8.4 已经变得相当老了,PostGIS 1.5 也是如此。

于 2013-01-22T07:35:44.087 回答