【发布时间】:2026-01-25 08:00:01
【问题描述】:
我在 PostGIS 中创建了一个表 itapp_cities,用于存储城市数据。我添加了一个数据类型为geometry 的列location 来存储一个城市的longitude 和latitude。当我运行以下 INSERT 查询时,我收到如下所示的错误。
INSERT查询:
INSERT INTO itapp_cities(city_id, city_name, city_code, state_id, location)
VALUES (DEFAULT,'Ada', 'ada-ok',37,POINT(34.774531000000003, -96.678344899999999));
表定义:
CREATE TABLE itapp_cities
(
city_id bigserial NOT NULL,
city_name character varying(100) NOT NULL,
city_code character varying(5) NOT NULL DEFAULT ''::character varying,
state_id bigint NOT NULL,
location geometry,
CONSTRAINT itapp_cities_pkey PRIMARY KEY (city_id),
CONSTRAINT fk_states FOREIGN KEY (city_id)
REFERENCES itapp_states (id) MATCH SIMPLE
ON UPDATE NO ACTION ON DELETE CASCADE
)
错误:
ERROR: column "location" is of type geometry but expression is of type point LINE 2: VALUES (DEFAULT,'Ada', 'ada-ok',37,POINT(34.77453100000000... ^ HINT: You will need to rewrite or cast the expression. ********** Error ********** ERROR: column "location" is of type geometry but expression is of type point SQL state: 42804
如何在此列中存储点值?我是 PostGIS 新手,请原谅我提出这个愚蠢的问题
【问题讨论】:
标签: database postgresql types postgis