Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-31829

LINESTRING() function creates a "linestring" from one point

    XMLWordPrintable

Details

    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?

      Attachments

        Activity

          People

            holyfoot Alexey Botchkov
            GeoffMontee Geoff Montee (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:

              Git Integration

                Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.