简体   繁体   English

为PostGIS编写原始SQL

[英]Write raw SQL for PostGIS

I'm trying to input some data into a PostgreSQL 8.4 database with a PostGIS template. 我正在尝试使用PostGIS模板将一些数据输入到PostgreSQL 8.4数据库中。 I'm unable to UPDATE polygons: 我无法UPDATE多边形:

> UPDATE my_table SET coords = POINT(1, 1)
UPDATE 0 1

> UPDATE my_table SET box = POLYGON(((1, 1), (2, 3), (3, 3), (1, 1)))
ERROR:  function polygon(record) does not exist

> UPDATE my_table SET box = POLYGON((1, 1), (2, 3), (3, 3), (1, 1))
ERROR:  function polygon(record, record, record, record) does not exist

> UPDATE my_table SET box = POLYGON(1, 1, 2, 3, 3, 3, 1, 1)
ERROR:  function polygon(numeric, numeric, numeric, numeric, numeric, numeric, numeric, numeric) does not exist

> UPDATE my_table SET box = ((1, 1), (2, 3), (3, 3), (1, 1))
ERROR:  column "box" is of type polygon but expression is of type record

How do I insert a polygon? 如何插入多边形? Note that the data already exists in the table, with NULL fields in place of the spatial data. 请注意,数据已经存在于表中,并且使用NULL字段代替空间数据。 I need to UPDATE , not INSERT , but that shouldn't make a difference. 我需要UPDATE而不是INSERT ,但这应该没有什么不同。

You should use the Geometry constructors to load new geometries in your table, specifically the St_GeomFromText function: 您应该使用Geometry构造函数在表中加载新的几何,特别是St_GeomFromText函数:

UPDATE my_table SET box = ST_GeomFromText('POLYGON ((1 1), (2 3), (3 3), (1 1))');

The geometry is defined in the WKT ( Well-Known Text ) format. 几何图形以WKT( 知名文本 )格式定义。

Try: 尝试:

UPDATE my_table SET box = '((1, 1), (2, 3), (3, 3), (1, 1))'::polygon;

To my knowledge, most geometric types in general need the quotes. 据我所知, 大多数几何类型通常都需要使用引号。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM