MySQL/POINT:修订间差异
来自康健生活
小 文字替换 -“{{leftrightflex|”替换为“{{Double-columns|” |
|||
| (未显示同一用户的9个中间版本) | |||
| 第4行: | 第4行: | ||
创建测试表和字段。 | 创建测试表和字段。 | ||
{{ | {{Double-columns|<syntaxhighlight lang="mysql"> | ||
CREATE TABLE `test-location` ( | CREATE TABLE `test-location` ( | ||
`id` int(11) NOT NULL AUTO_INCREMENT COMMENT '序号', | `id` int(11) NOT NULL AUTO_INCREMENT COMMENT '序号', | ||
| 第14行: | 第14行: | ||
</pre>}}}} | </pre>}}}} | ||
{{ | {{Double-columns|<syntaxhighlight lang="mysql"> | ||
INSERT INTO `test-location` (location, text) VALUES | INSERT INTO `test-location` (location, text) VALUES | ||
(ST_GeomFromText('POINT(100 200)'), '测试点1'), | (ST_GeomFromText('POINT(100 200)'), '测试点1'), | ||
| 第36行: | 第36行: | ||
); | ); | ||
</syntaxhighlight> | </syntaxhighlight> | ||
使用 mysql{{Version|5.6.48}} 测试坐标点。 | |||
{{Double-columns|<syntaxhighlight lang="mysql"> | |||
select geomfromtext('Point(10.1234 20.5678)'); | |||
</syntaxhighlight>|{{consoleout|<pre> | |||
AAAAAAEBAAAAHqfoSC4/JEA2qz5XW5E0QA== | |||
</pre>}}}} | |||
使用 mysql{{Version|8.0.28}} 测试坐标点。 | |||
{{Double-columns|<syntaxhighlight lang="mysql"> | |||
select st_geomfromtext('Point(10.1234 20.5678)'); | |||
</syntaxhighlight>|{{consoleout|<pre> | |||
+-------------------------------------------+ | |||
| st_geomfromtext('Point(10.2045 34.2379)') | | |||
+-------------------------------------------+ | |||
| POINT(10.2045 34.2379) | | |||
+-------------------------------------------+ | |||
1 row in set (0.00 sec) | |||
</pre>}}}} | |||
== 函数 == | == 函数 == | ||
=== Point(X,Y) === | |||
Point(X,Y) 是具有精确度的数字的构造函数,不需要先转换为文本,所以速度更快。 | |||
=== ST_GeomFromText === | === ST_GeomFromText === | ||
ST_GeomFromText(wkt, srid)可以返回 MySQL 支持的任何空间类型,可以用 WKT 表示。 | |||
=== ST_PointFromText === | === ST_PointFromText === | ||
ST_PointFromText(wkt, srid)POINT 来自 Well-known text的强类型构造函数。 | |||
== 查询数据 == | == 查询数据 == | ||
{{ | {{Double-columns|<syntaxhighlight lang="mysql"> | ||
SELECT | SELECT | ||
id, | id, | ||
| 第61行: | 第85行: | ||
ST_AsText | ST_AsText | ||
{{ | {{Double-columns|<syntaxhighlight lang="mysql"> | ||
SELECT id, ST_AsText(location), text FROM `test-location`;</syntaxhighlight>|{{consoleout|<pre> | SELECT id, ST_AsText(location), text FROM `test-location`;</syntaxhighlight>|{{consoleout|<pre> | ||
+----+---------------------+------------+ | +----+---------------------+------------+ | ||
| 第73行: | 第97行: | ||
== 更新数据 == | == 更新数据 == | ||
{{Double-columns|<syntaxhighlight lang="mysql"> | |||
update `test-location` set location=st_GeomFromText('POINT(123 100)') where id =1;</syntaxhighlight>|{{consoleout|<pre> | |||
Query OK, 1 row affected (0.01 sec) | |||
Rows matched: 1 Changed: 1 Warnings: 0 | |||
</pre>}}}} | |||