Postgres/Postgis - 如何在postgis中插入几何图形(postgis)

Postgres/Postgis - How to insert geometry in postges (postgis)

我想用 postgres (postgis) 将这个值插入到我的数据库中:

INSERT INTO test(
    id, shape)
    VALUES ('test', '<gml:LineString>
            <gml:coordinates>
                -71.16028,42.258729 -71.160837,42.259112 -71.161143,42.25932
            </gml:coordinates>
        </gml:LineString>');');

我的 table 测试:

CREATE TABLE test
(
    id character varying(32) COLLATE pg_catalog."default" NOT NULL,
    shape geometry,
)
WITH (
    OIDS = FALSE
)
TABLESPACE pg_default;

来源:https://postgis.net/docs/ST_GeomFromGML.html

记录错误:

ERROR:  parse error - invalid geometry
LINE 3:  VALUES ('test', '
                         ^
HINT:  "
        <g" <-- parse error at position 5 within geometry
SQL state: XX000
Character: 53

根据您链接到的documentation,您想要:

INSERT INTO test(id, shape)
    VALUES ('test', 
            ST_GeomFromGML('<gml:LineString>
                            <gml:coordinates>
                            -71.16028,42.258729 -71.160837,42.259112 -71.161143,42.25932
                            </gml:coordinates>
                            </gml:LineString>')
     );