将纬度、经度的MYSQL 5.7点表示插入表格中



我有一个如下表geom:

id (Int) not null (pk),
name (varchar 25),
timestamp (timestamp),
lat (decimal 6,4),
lon (decimal 6,4),
g (geometry),
pt (point)

我有另一个填充lat,lon字段的过程。

我想填充pt字段以利用5.7的地理空间扩展

如果我胖手指的lon,lat插入下面的插入语句是工作正常的:

set@g='point( -80.00 40.00)';
insert into geom (pt,timestamp) values (pointfromtext(@g),now());

但我想使用存储在该记录的lon,lat字段中的值

我可以使用concat语句创建看起来合适的值,但insert"pointfromtext"语句不会得到

的结果

使用构建SQL

CONCAT("point(", lon, ",", lat, ")")

如果你想覆盖整个世界,lon需要DECIMAL(7.4)

最新更新