我收到一条mySQL错误,提示“ ADDRESS_LONGI_LATIT_LOCATION”不能为null.
‘geomfromtext / pointfromtext’可能返回空值.怎么了任何帮助表示赞赏.
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'))
解决方法:
按照specification of ST_geomFromText()
(geomfromtext()是已弃用的同义词,您不应使用它):
If the geometry argument is
NULL
or not a syntactically well-formed geometry, or if the SRID argument isNULL
, the return value isNULL
.
确实,您的论点在语法上并不正确,因为每个坐标都包含两个点.您可以使用以下简单方法进行检查:
select geomfromtext('Point(10.20.45 34.23.79)')
结果(try online):
(null)
只要有一个点,它就可以工作:
select geomfromtext('Point(10.2045 34.2379)')
结果(true online)
AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==
同样适用于ST_PointFromText(()
,除了您仍然需要使用the WKT format,因此还需要使用POINT():
select pointfromtext('point(10.2045 34.2379)')
结果(try online):
AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==
基本上,这两个函数是相同的,除了pointfromtext()强制执行点结果.