POINT 列上的 MySQL 插入/更新

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5293062/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 19:06:17  来源:igfitidea点击:

MySQL INSERT/UPDATE on POINT column

mysqlsqlgeospatialspatialmysql-error-1416

提问by Luis D Urraca

I'm trying to populate my DB with geographical places of my country. One of my tables have 4 fields: ID[PK], latitude. longitude ande geoPoint

我正在尝试用我国家的地理位置填充我的数据库。我的一张表有 4 个字段:ID[PK]、纬度。经度和地理点

EDIT `SCDBs`.`Punto_Geografico`;

SET @lat = 18.469692;

SET @lon = -63.93212;

SET @g = 'POINT(@lat @lon)';

UPDATE Punto_Geografico SET latitude = @lat, longitude =@lon, geoPoint =@g WHERE idpunto_geografico = 0;

im getting the following error: Error Code: 1416 Cannot get geometry object from data you send to the GEOMETRY field

我收到以下错误:错误代码:1416 无法从发送到 GEOMETRY 字段的数据中获取几何对象

I'm pretty sure that 'geoPoint' field is a POINT field with a spatial index. Am i missing anything.14

我很确定 'geoPoint' 字段是一个带有空间索引的 POINT 字段。我是不是错过了什么。14

回答by FattyPotatoes

You need to use this syntax:

您需要使用以下语法:

UPDATE ... SET latitude=18, longitute=-63, geoPoint=GeomFromText('POINT(18 -63)') WHERE ...

回答by Marc B

Try doing it without assigning your values to server values. Especially if they contain function calls. MySQL treats the contents of the variables as plain text and won't see that there's a function call in there.

尝试在不将值分配给服务器值的情况下执行此操作。特别是如果它们包含函数调用。MySQL 将变量的内容视为纯文本,不会看到其中有函数调用。

UPDATE ... SET latitude=18, longitute=-63, geoPoint=POINT(18 -63) WHERE ...