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

相关推荐
Flynn Liang2 小时前
HikariCP 连接池不是越大越好:I/O 密集型 Java 服务的数据库容量工程
java·数据库·mysql·高并发·连接池·hikaricp·sql 优化
FungLeo3 小时前
FengCMS · PHP+MySQL 升级实录 ·三重 MD5 迁移 password_hash:老站密码怎么无痛升级
mysql·php·哈希算法·密码安全·fengcms
雾隐隐o3 小时前
优搭校园 01|项目概览、技术选型与初始化
spring boot·mysql·vue
小乖写代码3 小时前
消息、回执与媒体 · msgstore.db · Messages, Receipts, and Media
数据库·媒体·whatsapp·消息回执
GeW4 小时前
世界目光聚焦中国:底层技术、Linux、数据库的破局逻辑
linux·数据库
PingCAP5 小时前
平凯数据库 × 圣诺云数:让治理数据实时可用、跨域可信流通
数据库·tidb
利威尔xu5 小时前
PostgreSQL 索引失效 4 类:函数运算让查询全表扫描拖垮性能
开发语言·数据库·postgresql·性能优化·索引优化
PingCAP5 小时前
挚文集团(陌陌、探探)从 MySQL 分库分表到 TiDB 实时统一架构的实践
数据库·tidb
Decay__5 小时前
SQLServer 运维自动化平台 —— PowerShell + SQL Agent 作业:部署、监控、巡检、告警、工单闭环一体化
运维·数据库·sql·mysql·架构
杨凯凡6 小时前
Spring Framework 7 原生重试与并发限制实战:@Retryable、@ConcurrencyLimit 能替代 Resilience4j 吗?
数据库·spring·sqlserver