Skip to main content
deleted 4 characters in body
Source Link
danijar
  • 1.2k
  • 2
  • 12
  • 17
INSERT INTO tablename (id, name, area)
VALUES (
    'Lake',
    GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 179, 275 238, 131 240))', -1)
);
INSERT INTO tablename (id, name, area)
VALUES (
    'Lake',
    GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 179, 275 238, 131 240))', -1)
);
INSERT INTO tablename (name, area)
VALUES (
    'Lake',
    GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 179, 275 238, 131 240))', -1)
);
corrected error message
Source Link
danijar
  • 1.2k
  • 2
  • 12
  • 17
ERROR:  syntax error at or near "INTO"
LINE 1: SELECT COUNT(*) AS total FROM (INSERT INTO tablename (id, na...
                                              ^
ERROR:  function geometryfromtext(unknown, integer) does not exist
LINE 4:     GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 ...
            ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
ERROR:  syntax error at or near "INTO"
LINE 1: SELECT COUNT(*) AS total FROM (INSERT INTO tablename (id, na...
                                              ^
ERROR:  function geometryfromtext(unknown, integer) does not exist
LINE 4:     GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 ...
            ^
HINT:  No function matches the given name and argument types. You might need to add explicit type casts.
Source Link
danijar
  • 1.2k
  • 2
  • 12
  • 17

Cannot insert simple geometry data

I installed PostgreSQL 9.2.4 and PostGIS 2.0.3 on my Windows 8 machine. Then I created a table using phpPgAdmin and added a geometry column using the following statement.

SELECT AddGeometryColumn('tablename', 'area', -1, 'POLYGON', 2);

That resulted in these table columns.

+------+---------------------+--------+----------------------------------+-----------+
|Column|Type                 |Not Null|Default                           |Constraints|
+------+---------------------+--------+----------------------------------+-----------+
|id    |integer              |NOT NULL|nextval('simple_id_seq'::regclass)|PRIMARY KEY|
|name  |character varying(50)|        |                                  |           |
|area  |geometry(Polygon)    |        |                                  |           |
+------+---------------------+--------+----------------------------------+-----------+

After some simple text queries I tried to play with geometry data. This is the query I tried to execute.

INSERT INTO tablename (id, name, area)
VALUES (
    'Lake',
    GeometryFromText('POLYGON((84 104, 212 48, 321 122, 243 179, 275 238, 131 240))', -1)
);

Unfortunately, it throws an error message.

ERROR:  syntax error at or near "INTO"
LINE 1: SELECT COUNT(*) AS total FROM (INSERT INTO tablename (id, na...
                                              ^

Since AddGeometryColumn was successful, I assume that PostGIS is set up properly. How can I insert geometry data in my table? What am I doing wrong?