[MDEV-31829] LINESTRING() function creates a "linestring" from one point Created: 2023-08-02  Updated: 2023-11-28

Status: Open
Project: MariaDB Server
Component/s: Data types, GIS
Affects Version/s: 10.6.14
Fix Version/s: 10.4, 10.5, 10.6, 10.11, 11.0, 11.1

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Alexey Botchkov
Resolution: Unresolved Votes: 0
Labels: None


 Description   

For GIS/Geometry types, constructor functions are provided. For example, for the LINESTRING data type, the LineString() constructor function can be used to construct a LINESTRING value. Currently, when MariaDB Server tries to cast or convert a value from one geometry type to another (either implicitly or explicitly), different rules appear to be used.

I only tested this on 10.6, but I assume this issue is present on all versions.

Steps to reproduce

Create some objects:

CREATE DATABASE db1;
 
USE db1;
 
CREATE TABLE linestring_example (
   g LINESTRING
);

Try out some different operations:

-- 1.) explicitly call constructor function
INSERT INTO linestring_example VALUES (LineString(Point(1,1)));
-- 2.) implicit conversion from POINT to LINESTRING
INSERT INTO linestring_example VALUES (Point(1,1));
-- 3.) explicit cast from POINT to LINESTRING
INSERT INTO linestring_example VALUES (CAST(Point(1,1) AS LINESTRING));
-- 4.) explicit conversion from POINT to LINESTRING
INSERT INTO linestring_example VALUES (CONVERT(Point(1,1), LINESTRING));

Actual results

The only statement that works is the one that explicitly calls the constructor function:

MariaDB [db1]> -- 1.) explicitly call constructor function
MariaDB [db1]> INSERT INTO linestring_example VALUES (LineString(Point(1,1)));
Query OK, 1 row affected (0.009 sec)
 
MariaDB [db1]> -- 2.) implicit conversion from POINT to LINESTRING
MariaDB [db1]> INSERT INTO linestring_example VALUES (Point(1,1));
ERROR 1366 (22007): Incorrect LINESTRING value: 'POINT(1 1)' for column `db1`.`linestring_example`.`g` at row 1
MariaDB [db1]> -- 3.) explicit cast from POINT to LINESTRING
MariaDB [db1]> INSERT INTO linestring_example VALUES (CAST(Point(1,1) AS LINESTRING));
ERROR 4162 (HY000): Operator does not exists: 'CAST(expr AS linestring)'
MariaDB [db1]> -- 4.) explicit conversion from POINT to LINESTRING
MariaDB [db1]> INSERT INTO linestring_example VALUES (CONVERT(Point(1,1), LINESTRING));
ERROR 4162 (HY000): Operator does not exists: 'CAST(expr AS linestring)'

Expected results

Should all of these cases use similar conversion rules?



 Comments   
Comment by Sergei Golubchik [ 2023-09-10 ]

The manual says

Constructs a WKB LineString value from a number of WKB Point arguments. If any argument is not a WKB Point, the return value is NULL. If the number of Point arguments is less than two, the return value is NULL.

Apparently the current behavior contradicts this.

Generated at Thu Feb 08 10:26:46 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.