mysql使用st_distance_sphere函数报错Incorrect arguments to st_distance_sphere

最近发现执行mysql st_distance_sphere报错了。

报错的信息是Incorrect arguments to st_distance_sphere。

最开始以为是跟mysql的版本有关系,所以看了下自己本地的mysql版本,执行一下sql

复制代码
select version();

发现自己本地的mysql版本是

5.7.30

这个版本是支持st_distance_sphere函数的。

但是,仍旧报错,后来考虑使用st_distance,st_distance函数执行是不会报错的。

查了下,st_distance_sphere是比st_distance相对更精确些,所以就抱着精确的心理,看看如何解决执行st_distance_sphere函数报错的问题。

最后,发现了原因,在处理数据将数据插入到mysql的脚本中

复制代码
`location` point NOT NULL

location的字段存储的point数据,没有按照要求存储,错误的存储成POINT(纬度 经度),正确的应该存储城经度在前,纬度在后,正确的格式数据如下图

其实英文原文的文档中也有对这个描述

SQL Error (1210): Incorrect arguments to st_distance_sphere

The geometry arguments should consist of points that specify (longitude, latitude) coordinate values: Longitude and latitude are the first and second coordinates of the point, respectively. Both coordinates are in degrees

相关推荐
身如柳絮随风扬20 分钟前
MongoDB 典型使用场景深度解析:从订单冷热分离到社交地理查询
数据库·mongodb
minji...37 分钟前
MySQL数据库 (一) MySQL数据库基础,MySQL架构,存储引擎,SQL语句分类
数据库·mysql·oracle·sql语句·存储引擎··mysqld
baynk1 小时前
深入理解MySQL事务隔离级别:从理论到实战实验
mysql
jason_renyu1 小时前
MySQL横表(直表/宽表)与竖表(键值表)完整实操学习笔记
mysql·mysql学习·横标和竖表·竖表讲解·横标竖表学习
梦想的颜色1 小时前
MySQL 查询性能核武器
运维·服务器·数据结构·数据库·mysql
haven-8522 小时前
mysql索引当中的B+树,聚簇/二级索引,最左匹配,失效场景
数据库·b树·mysql
jason_renyu2 小时前
MySQL数据表设计入门学习文档(基于Flask+Vue3图书馆管理系统·小白专用)
mysql·数据表设计入门学习·mysql数据库表设计学习·新手入门数据表设计
KaiwuDB3 小时前
KWDB SampleDB 上新|用 Agent Skill 跑通数据库示例
数据库
计算机安禾3 小时前
【算法分析与设计】第43篇:空间复杂度类与Savitch定理
java·服务器·网络·数据库·算法
cui_ruicheng4 小时前
MySQL(一):数据库基础与MySQL入门
数据库·sql·mysql