0

From the docs on MariaDB, for ST_LineStringFromText

Constructs a LINESTRING value using its WKT representation and SRID.

ST_LineFromText(), ST_LineStringFromText(), ST_LineFromText() and ST_LineStringFromText() are all synonyms.

It seems to be technically incorrect though, for example here we construct a point and a polygon using ST_LineStringFromText(),

WITH t(geom) AS ( VALUES
  (ST_LineStringFromText('POLYGON ((35 10, 45 45, 15 40, 10 20, 35 10),(20 30, 35 35, 30 20, 20 30))')),
  (ST_LineStringFromText('POINT( 0 0 )')),
  (ST_LineStringFromText('LINESTRING( 0 0, 1 1 )'))
)
SELECT ST_AsText(geom)
FROM t;

Returns..

POLYGON((35 10,45 45,15 40,10 20,35 10),(20 30,35 35,30 20,20 30))
POINT(0 0)
LINESTRING(0 0,1 1)

The Polygon functions are just as confusingly documented,

Constructs a POLYGON value using its WKT representation and SRID.

ST_PolyFromText(), ST_PolygonFromText(), PolyFromText() and ST_PolygonFromText() are all synonyms.

Yet you can replace ST_LineStringFromText with ST_PolyFromText and they work the same way.

MySQL Behavior

With MySQL 8 you seem to get an error on the above construction,

WKT value is a geometry of unexpected type POINT in st_linestringfromtext.

0

However cute and undocumented, all these functions map internally to Create_func_geometry_from_text in item_create.cc,. For this reason, I would advise using ST_GeomFromText() which best reflects that.

GEOMCOLLFROMTEXT
GEOMETRYCOLLECTIONFROMTEXT
GEOMETRYFROMTEXT
GEOMFROMTEXT
LINEFROMTEXT
LINESTRINGFROMTEXT
MLINEFROMTEXT
MPOINTFROMTEXT
MPOLYFROMTEXT
MULTILINESTRINGFROMTEXT
MULTIPOINTFROMTEXT
MULTIPOLYGONFROMTEXT
POINTFROMTEXT
POLYFROMTEXT
POLYGONFROMTEXT
ST_GEOMCOLLFROMTEXT
ST_GEOMETRYCOLLECTIONFROMTEXT
ST_GEOMETRYFROMTEXT
ST_GEOMFROMTEXT
ST_LINEFROMTEXT
ST_LINESTRINGFROMTEXT
ST_MLINEFROMTEXT
ST_MPOINTFROMTEXT
ST_MPOLYFROMTEXT
ST_MULTILINESTRINGFROMTEXT
ST_MULTIPOINTFROMTEXT
ST_MULTIPOLYGONFROMTEXT
ST_POINTFROMTEXT
ST_POLYFROMTEXT
ST_POLYGONFROMTEXT

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.