MySQL/POINT:修订间差异
来自康健生活
< MySQL
| 第40行: | 第40行: | ||
=== ST_GeomFromText === | === ST_GeomFromText === | ||
=== ST_PointFromText === | === ST_PointFromText === | ||
== 查询数据 == | |||
{{leftrightflex|<syntaxhighlight lang="mysql"> | |||
SELECT | |||
id, | |||
ST_x(location) x, | |||
ST_y(location) y, | |||
location, | |||
text | |||
FROM `test-location`; | |||
</syntaxhighlight>|{{consoleout|<pre> | |||
+----+-----+-----+----------------+------------+ | |||
| id | x | y | location | text | | |||
+----+-----+-----+----------------+------------+ | |||
| 1 | 100 | 200 | POINT(100 200) | 测试点1 | | |||
| 2 | 300 | 500 | POINT(300 500) | 测试点2 | | |||
+----+-----+-----+----------------+------------+ | |||
2 rows in set (0.01 sec) | |||
</pre>}}}} | |||
2022年8月9日 (二) 09:53的版本
测试数据
mysql 之后的版本,空间数据类型的操作函数在命名上统一在前面加上
ST,如 GeomFromText 改为 ST_GeomFromText。创建测试表和字段。
添加数据还可以使用其他语句。
SET @tempdata = 'POINT(100 100)';
INSERT INTO `test-location`(location, text) VALUES (
ST_GeomFromText(@tempdata),
'测试点3'
);
/** or **/
SET @tempdata = ST_GeomFromText('POINT(100 100)');
INSERT INTO `test-location`(location, text) VALUES (
@tempdata,
'测试点4'
);
函数
ST_GeomFromText
ST_PointFromText
查询数据
No categories