Append a Point to a LineString in MySQL

SET @ls = LineString(Point(0, 0), Point(0, 1));

WITH RECURSIVE
nums (n) AS (SELECT 1 UNION ALL SELECT n + 1 FROM nums WHERE n < ST_NumPoints(@ls)),
points (p) as (SELECT ST_PointN(@ls, n) FROM nums UNION ALL SELECT Point(2, 3))
SELECT CAST(ST_Collect(p) AS LINESTRING) INTO @ls FROM points;

SELECT ST_AsText(@ls);

+-------------------------+
| ST_AsText(@ls) |
+-------------------------+
| LINESTRING(0 0,0 1,2 3) |
+-------------------------+

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.