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

相关推荐
先吃饱再说6 小时前
存储的进化:从 MySQL 到浏览器缓存,数据到底住在哪?
数据库
Nturmoils6 小时前
字段太多看不全,ksql 的展开模式和输出控制怎么用
数据库·后端
Databend9 小时前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent
这个DBA有点耶9 小时前
SQL改写进阶:标量子查询的“隐形代价”与消除实战
数据库·mysql·架构
smallyoung10 小时前
数据库乐观锁深度解析:MySQL、PostgreSQL 实战 + Spring Boot 集成指南
数据库·mysql·postgresql
parade岁月10 小时前
MySQL JOIN解析:朴实无华但食之有味
数据库·后端
用户31693538118311 小时前
MySQL服务无法启动问题解决全记录
数据库
vivo互联网技术14 小时前
从 10 分钟到 1 秒:ES 深度分页任意跳页的三轮优化实战
服务器·数据库·redis·elasticsearch·深度分页
数据技术说15 小时前
MySQL 迁移实战——如何实现真正的"零改造"平滑切换
mysql
倔强的石头_1 天前
《Kingbase护城河》——猎捕慢查询:执行计划的微观解析与索引调优实战
数据库