我想从我现有的两列中制作第三列。假设我当前的表(坐标)如下所示:
(table: coords)
+----------------+------+
| x | y |
+----------------+------+
| 1 | 0 |
+----------------+------+
| 1 | 1 |
+----------------+------+
我想从其他两列中创建第三列几何类型(来自PostGIS)并将此列添加到该表中。决赛桌应如下所示:
(table: pointsT)
+-----+----------+------+----+-----
| x | y | coord |
+----------------+------+----------
| 1 | 0 | (1, 0) |
+----------------+------+----------
| 1 | 1 | (1, 1) |
+----------------+------+----------
我想从中创建一个表。就像是:
CREATE TABLE pointsT(x text, y text, point geometry);
INSERT INTO points(x, y, point)
SELECT CO.x, CO.y, CO.'POINT(CO.x CO.y)' AS p FROM coords AS CO;
编辑:来自 Edwins Answer Using Edwins answer,这将是完整的命令:
CREATE TABLE pointsT(x text, y text, point geometry);
INSERT INTO points(x, y, point)
SELECT CO.x, CO.y, ST_AsText(ST_SetSRID(ST_Point(CO.x CO.y), 4326) AS wgs84long_la FROM coords AS CO;