2

In MySQL < 5.7 the spatial functions returned NULL when given invalid WKT, eg:

mysql> select astext(geomfromtext('polygon()'));

+-----------------------------------+
| astext(geomfromtext('polygon()')) |
+-----------------------------------+
| NULL                              |
+-----------------------------------+
1 row in set (0.00 sec)

But with newer MySQL the same input gives:

ERROR 3037 (22023): Invalid GIS data provided to function st_geometryfromtext.

Is there a way of checking whether the WKT is valid before sending it to the geometry functions? Alternatively is there a setting to force the geometry functions to produce NULL rather than error for invalid input?

Simon Nuttall
  • 394
  • 1
  • 3
  • 12

1 Answers1

3

there are two functions provided by MySQL to test validity of geometries, but both take an already formed geometry as input.

ST_IsValid(ST_GeomFromText(?)); returns a boolean

ST_Validate(ST_GeomFromText(?)); returns the GEOM or null if invalid.

there is nothing I know of that parses WKT in MySQL, nor is there a setting that will switch it back to <5.7 behaviour.

O'malley
  • 31
  • 3