我收到一个 mySQL 错误,提示“ADDRESS_LONGI_LATIT_LOCATION”不能为空。 “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()
强制一个点结果。
关于mysql - 如何在mySQL表中插入点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52060290/