How do I create a point with an SRID in MySQL?
Question
MySQL supports using ST_PointFromText
to construct a point with an SRID,
ST_PointFromText(wkt[, srid [, options]])
Constructs a Point value using its WKT representation and SRID.
This assumes the input is Well-Known Text (WKT). How do I construct a point with latitude and longitude as doubles (or floating point types).
Solution
MySQL 8.0+
MySQL supports Point(x,y)
which is a GIS function that constructs a point. With MySQL 8.0 and newer, you can further assign an SRID to that point with ST_SRID(srid)
SELECT ST_SRID( Point(0,0), 4326);
This is a relatively new feature implemented in MySQL 8.0 with #WL8543. MariaDB does not support it.
In PostGIS, you would use,
SELECT ST_SetSRID( ST_MakePoint(0,0), 4326);
In MariaDB, your only option is,
ST_PointFromText(wkt[, srid [, options]])
Licensed under: CC-BY-SA with attribution
Not affiliated with dba.stackexchange