如何在 mySQL table 中插入点

How to insert point in mySQL table

我收到一个 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 is NULL, the return value is NULL.

确实,您的论点在语法上不合式,因为每个坐标包含两个点。你可以用一个简单的检查:

select geomfromtext('Point(10.20.45 34.23.79)')

结果(try online):

(null)

用一个点就可以了:

select geomfromtext('Point(10.2045 34.2379)')

结果 (true online)

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==

同样适用于ST_PointFromText((), except you still need to use the WKT format所以你也需要使用POINT():

select pointfromtext('point(10.2045 34.2379)')

结果(try online):

AAAAAAEBAAAAYhBYObRoJED129eBcx5BQA==

基本上这两个功能是相同的,除了pointfromtext()强制一个点结果。