views:

33

answers:

2

I'm trying to input some data into a PostgreSQL 8.4 database with a PostGIS template. I'm unable to UPDATE polygons:

> 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. I need to UPDATE, not INSERT, but that shouldn't make a difference.

+1  A: 

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.

rfusca
+1  A: 

You should use the Geometry constructors to load new geometries in your table, specifically the St_GeomFromText function:

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.

amercader
Yes, I like writing in WKT, I just didn't know about the constructor...
Attila Oláh