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

Polymorphic Data Types for Functions

    XMLWordPrintable

    Details

    • Type: Task
    • Status: Open (View Workflow)
    • Priority: Major
    • Resolution: Unresolved
    • Fix Version/s: None
    • Component/s: Stored routines
    • Labels:
      None

      Description

      Support for polymorphic data types in stored functions would be useful. Postgres has ANY, ANYELEMENT, ANYNONARRAY for this: https://www.postgresql.org/docs/9.1/extend-type-system.html

      Without this, it's not at the moment possible to create functions which use operators correctly, no matter which datatype was used at the call site. As MariaDB also does not support overloading of functions depending on the types, there's no way to currently fix this.

      A non-sensical example illustrating what I want to achieve (vastly simplified):

      CREATE OR REPLACE FUNCTION cmp( a, b) RETURNS BOOLEAN
      BEGIN
          DECLARE tmp BOOLEAN;
          SELECT a < b INTO tmp;
          RETURN tmp;
      END
      

      No matter which data type I currently use in MariaDB for declaring the function, it will only work for the declared type. If declaring the above with type TEXT and calling with actual numeric types: select cmp(2,10);, parameters will be converted to TEXT first, leading to a text-like instead of numerical comparison. If I use a more specific type, the function will not work at all for the other types.

        Attachments

          Activity

            People

            Assignee:
            Unassigned
            Reporter:
            warp Markus Peter
            Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

              Dates

              Created:
              Updated: