如何在mySQL表中插入点 [英] How to insert point in mySQL table

查看:145
本文介绍了如何在mySQL表中插入点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到一条mySQL错误,提示"ADDRESS_LONGI_LATIT_LOCATION"不能为null. 'geomfromtext/pointfromtext'可能返回空值.怎么了感谢您的帮助.

I get an mySQL error saying 'ADDRESS_LONGI_LATIT_LOCATION' can not be null. Likely that 'geomfromtext/pointfromtext' is returning a null. Whats wrong here? Any help is appreciated.

INSERT INTO address (ADDRESS_NICKNAME,ADDRESS_LONGI_LATIT_LOCATION) 
VALUES ('Testing',geomfromtext('Point(10.20.45 34.23.79)'))

另一种方式

INSERT INTO address (ADDRESS_NICKNAME,ADDRESS_LONGI_LATIT_LOCATION) 
VALUES ('Testing',pointfromtext('10.20.45 34.23.79'))

推荐答案

按照

As per the specification of ST_geomFromText() (geomfromtext() is a deprecated synonym, you should not use it):

如果geometry参数是NULL或不是语法上格式正确的几何,或者SRID参数是NULL,则返回值是NULL.

If the geometry argument is NULL or not a syntactically well-formed geometry, or if the SRID argument is NULL, the return value is NULL.

实际上,您的论点的语法格式不正确,因为每个坐标都包含两个点.您可以使用以下简单方法进行检查:

Indeed your argument is not syntactically well-formed, as each coordinate contains two dots. You can check this with a simple:

select geomfromtext('Point(10.20.45 34.23.79)')

结果(尝试在线):

(空)

只有一个点,它可以工作:

With a single dot, it works:

select geomfromtext('Point(10.2045 34.2379)')

结果(真正在线)

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA ==

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==

ST_PointFromText(() ,除了您仍然需要使用 WKT格式,因此您还需要使用POINT():

The same applies to ST_PointFromText((), except you still need to use the WKT format so you need to use POINT() as well:

select pointfromtext('point(10.2045 34.2379)')

结果(尝试在线):

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA ==

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==

这两个函数基本上相同,除了pointfromtext()会强制得出点结果.

Basically the two functions are the same, except pointfromtext() enforces a point result.

这篇关于如何在mySQL表中插入点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆