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

相关推荐
草莓熊Lotso1 小时前
【Redis 初阶】Set 类型深度解析:去重集合的运算能力与实战场景
linux·网络·数据库·windows·redis·tcp/ip·缓存
煎饼皮皮侠3 小时前
【设计】设计一个web版的数据库管理平台后端(之五) --借鉴mybatis
数据库·mybatis
东风破_9 小时前
danci 2:创建的单词书到底存在哪里?从 Supabase 一路理解 ORM、Drizzle 和 RLS
数据库·后端·node.js
九皇叔叔10 小时前
《MySQL 体系架构详解:Server 层、SQL 执行流程与 InnoDB、MyISAM、MEMORY 存储引擎》
sql·mysql·架构
橙子家10 小时前
OSS 文件上传的几个风险点和解决方案
数据库
2601_9620664912 小时前
【Sql Server】Update中的From语句,以及常见更新操作方式
android·java·数据库
愤怒的苹果ext12 小时前
MySQL Shell备份恢复数据库
数据库·mysql·备份恢复·mysqlsh
数字新视界14 小时前
DCIM管理系统的技术架构与部署模式详解
数据库·物联网·数据中心·数据中心基础设施管理·dcim管理系统
何以解忧,唯有..14 小时前
Pydantic 介绍与使用:Python 数据校验的现代方案
数据库·python·microsoft
超兔一体云15 小时前
MySQL索引优化实战——从慢查询到索引调优
后端·mysql