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

Add optional correlation column list for derived tables

Details

    Description

      In MariaDB for table value constructors, the column names are taken from the value of the first set of results

      MariaDB [test]> values (3,4),(5,6);
      +---+---+
      | 3 | 4 |
      +---+---+
      | 3 | 4 |
      | 5 | 6 |
      +---+---+
      2 rows in set (0.002 sec)
      

      There is no mechanism to assign them names. The SQL standard tells us that the column name(s) for a table value expression is "implementation dependent".

      PostgreSQL can (re)assign column names in the derived table name syntax element.

      rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
       col1 | col2 
      ------+------
          3 |    4
          5 |    6
      (2 rows)
       
      rex=# select * from (select concat(col1, col2)  from (values (3,4)) as foo(col1,col2)) as foo2 (a);
       a  
      ----
       34
      (1 row)
      
      

      This is similar to the syntax used in the specification of a CTE, i.e.

      MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
      +---+---+
      | a | b |
      +---+---+
      | 3 | 4 |
      | 5 | 6 |
      +---+---+
      2 rows in set (0.005 sec)
      

      The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
      Note the option of this being <derived table> <correlation or recognition>
      where <derived table> translates into '(' <query expression> ')'.

      <table primary> ::=
          <table or query name>
          [ <query system time period specification> ]
          [ <correlation or recognition> ]
        | <derived table> <correlation or recognition>
        | <lateral derived table> <correlation or recognition>
        | <collection derived table> <correlation or recognition>
        | <table function derived table> <correlation or recognition>
        | <PTF derived table> [ <correlation or recognition> ]
        | <only spec> [ <correlation or recognition> ]
        | <data change delta table> [ <correlation or recognition> ]
        | <JSON table> <correlation or recognition>
        | <JSON table primitive> <correlation name>
        | <parenthesized joined table>
       
      <correlation or recognition> ::=
        [ AS ] <correlation name>
        [ <parenthesized derived column list> ]
       
      <parenthesized derived column list> ::=
        <left paren> <derived column list> <right paren>
       
      <derived column list> ::=
        <column name list>
       
      <column name list> ::=
        <column name> [ { <comma> <column name> }... ]
      

      The MDEV covers the implementation of this for MariaDB.

      Attachments

        Issue Links

          Activity

            Johnston Rex Johnston created issue -
            Johnston Rex Johnston made changes -
            Field Original Value New Value
            Assignee Rex Johnston [ JIRAUSER52533 ]
            Johnston Rex Johnston made changes -
            Fix Version/s 11.2 [ 28603 ]
            Johnston Rex Johnston made changes -
            Status Open [ 1 ] In Progress [ 3 ]
            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            A popular alternative can assign the names at the level of a derived table.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)
            {code}

            It is proposed that we follow this standard.
            <fill in details about the standard here>

            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            A popular alternative database can assign the names at the level of a derived table.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)
            {code}

            It is proposed that we follow this standard.
            <fill in details about the standard here>

            what "popular alternative database"? What does the standard say?

            serg Sergei Golubchik added a comment - what "popular alternative database"? What does the standard say?
            serg Sergei Golubchik made changes -
            Fix Version/s 11.3 [ 28565 ]
            Fix Version/s 11.2 [ 28603 ]
            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            A popular alternative database can assign the names at the level of a derived table.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)
            {code}

            It is proposed that we follow this standard.
            <fill in details about the standard here>

            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            A popular database (PostgreSQL) can assign the names at the level of a derived table.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)
            {code}

            It is proposed that we follow this standard.
            <fill in details about the standard here>

            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            A popular database (PostgreSQL) can assign the names at the level of a derived table.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)
            {code}

            It is proposed that we follow this standard.
            <fill in details about the standard here>

            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            It is proposed that we follow this standard.



            Johnston Rex Johnston made changes -
            Priority Major [ 3 ] Minor [ 4 ]
            serg Sergei Golubchik made changes -
            Priority Minor [ 4 ] Critical [ 2 ]
            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            It is proposed that we follow this standard.



            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, page 406 describes this syntax

            {noformat}
            <table primary> ::=
                <table or query name>
              [ <query system time period specification> ]
              [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]

            {noformat}


            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, page 406 describes this syntax

            {noformat}
            <table primary> ::=
                <table or query name>
              [ <query system time period specification> ]
              [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]

            {noformat}


            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax

            {noformat}
            <table primary> ::=
                <table or query name>
              [ <query system time period specification> ]
              [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]

            {noformat}


            Johnston Rex Johnston made changes -
            Comment [ The 2016 SQL Foundation Document, page 1598
            26) Subclause 7.3, “<table value constructor>”:
            a) The column names of a <table value constructor> or a <contextually typed table value constructor> are implementation-dependent. ]
            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax

            {noformat}
            <table primary> ::=
                <table or query name>
              [ <query system time period specification> ]
              [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]

            {noformat}


            Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
            Note the option of this being <derived table> <correlation or recognition>
            where <derived table> translates into '(' <query expression> ')'.

            {noformat}
            <table primary> ::=
                <table or query name>
                [ <query system time period specification> ]
                [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]
            {noformat}


            Johnston Rex Johnston made changes -
            Summary Implement column names for Table Value Expressions Optional column name specification for derived tables.
            Johnston Rex Johnston made changes -
            Description Implement column names for Table Value Expressions.

            currently column names are simply taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is currently no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
            Note the option of this being <derived table> <correlation or recognition>
            where <derived table> translates into '(' <query expression> ')'.

            {noformat}
            <table primary> ::=
                <table or query name>
                [ <query system time period specification> ]
                [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]
            {noformat}


            The SQL standard tells us that the column name(s) for a table value expression is "implementation dependent".
            In MariaDB, the column names are taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
            Note the option of this being <derived table> <correlation or recognition>
            where <derived table> translates into '(' <query expression> ')'.

            {noformat}
            <table primary> ::=
                <table or query name>
                [ <query system time period specification> ]
                [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]
            {noformat}

            The MDEV covers the implementation of this for MariaDB.
            Johnston Rex Johnston made changes -
            Johnston Rex Johnston made changes -
            Summary Optional column name specification for derived tables. Implement column name assignment for derived table expressions.
            Johnston Rex Johnston made changes -
            Johnston Rex Johnston made changes -
            Johnston Rex Johnston made changes -
            Summary Implement column name assignment for derived table expressions. add optional
            Johnston Rex Johnston made changes -
            Summary add optional add optional [<parenthesized derived column list>] to <derived table> [ AS ] <correlation name>
            Johnston Rex Johnston made changes -
            Description The SQL standard tells us that the column name(s) for a table value expression is "implementation dependent".
            In MariaDB, the column names are taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is no mechanism to assign them names.

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
            Note the option of this being <derived table> <correlation or recognition>
            where <derived table> translates into '(' <query expression> ')'.

            {noformat}
            <table primary> ::=
                <table or query name>
                [ <query system time period specification> ]
                [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]
            {noformat}

            The MDEV covers the implementation of this for MariaDB.
            In MariaDB for table value constructors, the column names are taken from the value of the first set of results

            {code:SQL}
            MariaDB [test]> values (3,4),(5,6);
            +---+---+
            | 3 | 4 |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.002 sec)
            {code}

            There is no mechanism to assign them names. The SQL standard tells us that the column name(s) for a table value expression is "implementation dependent".

            PostgreSQL can (re)assign column names in the derived table name syntax element.

            {code:SQL}
            rex=# select * from (values (3,4),(5,6)) as foo(Col1, Col2);
             col1 | col2
            ------+------
                3 | 4
                5 | 6
            (2 rows)

            rex=# select * from (select concat(col1, col2) from (values (3,4)) as foo(col1,col2)) as foo2 (a);
             a
            ----
             34
            (1 row)

            {code}

            This is similar to the syntax used in the specification of a CTE, i.e.

            {code:SQL}
            MariaDB [test]> WITH cte(a,b) as (values (3,4),(5,6) ) select * from cte ;
            +---+---+
            | a | b |
            +---+---+
            | 3 | 4 |
            | 5 | 6 |
            +---+---+
            2 rows in set (0.005 sec)
            {code}

            The SQL (2016) Foundation document, (starting at page 406) describes this syntax for the <table primary> syntax element.
            Note the option of this being <derived table> <correlation or recognition>
            where <derived table> translates into '(' <query expression> ')'.

            {noformat}
            <table primary> ::=
                <table or query name>
                [ <query system time period specification> ]
                [ <correlation or recognition> ]
              | <derived table> <correlation or recognition>
              | <lateral derived table> <correlation or recognition>
              | <collection derived table> <correlation or recognition>
              | <table function derived table> <correlation or recognition>
              | <PTF derived table> [ <correlation or recognition> ]
              | <only spec> [ <correlation or recognition> ]
              | <data change delta table> [ <correlation or recognition> ]
              | <JSON table> <correlation or recognition>
              | <JSON table primitive> <correlation name>
              | <parenthesized joined table>

            <correlation or recognition> ::=
              [ AS ] <correlation name>
              [ <parenthesized derived column list> ]

            <parenthesized derived column list> ::=
              <left paren> <derived column list> <right paren>

            <derived column list> ::=
              <column name list>

            <column name list> ::=
              <column name> [ { <comma> <column name> }... ]
            {noformat}

            The MDEV covers the implementation of this for MariaDB.
            igor Igor Babaev (Inactive) made changes -
            Summary add optional [<parenthesized derived column list>] to <derived table> [ AS ] <correlation name> Add optional correlation column list for derived tables
            serg Sergei Golubchik made changes -
            Fix Version/s 11.4 [ 29301 ]
            Fix Version/s 11.3 [ 28565 ]
            Johnston Rex Johnston made changes -
            serg Sergei Golubchik made changes -
            Fix Version/s 11.5 [ 29506 ]
            Fix Version/s 11.4 [ 29301 ]
            julien.fritsch Julien Fritsch made changes -
            Status In Progress [ 3 ] Stalled [ 10000 ]
            Johnston Rex Johnston made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            Johnston Rex Johnston made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Igor Babaev [ igor ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.6 [ 29515 ]
            Fix Version/s 11.5 [ 29506 ]
            Johnston Rex Johnston made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]
            Johnston Rex Johnston made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            Johnston Rex Johnston made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            Johnston Rex Johnston added a comment - - edited

            Hi igor, please review github.com/MariaDB/server/tree/bb-11.6MDEV-31466-
            Thanks, Rex

            [Edit] This tree has been removed, current tree is https://github.com/MariaDB/server/tree/bb-11.7-MDEV-31466

            Johnston Rex Johnston added a comment - - edited Hi igor , please review github.com/MariaDB/server/tree/bb-11.6 MDEV-31466 - Thanks, Rex [Edit] This tree has been removed, current tree is https://github.com/MariaDB/server/tree/bb-11.7-MDEV-31466
            Johnston Rex Johnston made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Igor Babaev [ igor ]
            Status In Progress [ 3 ] In Review [ 10002 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]
            Johnston Rex Johnston made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Igor Babaev [ igor ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.7 [ 29815 ]
            Fix Version/s 11.6 [ 29515 ]
            Johnston Rex Johnston made changes -
            serg Sergei Golubchik made changes -
            Priority Critical [ 2 ] Major [ 3 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]

            Johnston Please find my feedback in your mail box.

            igor Igor Babaev (Inactive) added a comment - Johnston Please find my feedback in your mail box.
            Johnston Rex Johnston made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            Johnston Rex Johnston made changes -
            Status Stalled [ 10000 ] In Progress [ 3 ]
            serg Sergei Golubchik made changes -
            Issue Type Task [ 3 ] New Feature [ 2 ]
            serg Sergei Golubchik made changes -
            Priority Major [ 3 ] Critical [ 2 ]
            Johnston Rex Johnston made changes -
            Status In Progress [ 3 ] In Testing [ 10301 ]
            Johnston Rex Johnston made changes -
            Status In Testing [ 10301 ] Stalled [ 10000 ]
            Johnston Rex Johnston made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Igor Babaev [ igor ]
            Status Stalled [ 10000 ] In Review [ 10002 ]
            Johnston Rex Johnston made changes -
            Status In Review [ 10002 ] In Testing [ 10301 ]
            Johnston Rex Johnston made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]
            Johnston Rex Johnston made changes -
            Comment [ Hi Igor, please review https://github.com/MariaDB/server/tree/bb-11.7-MDEV-31466.
            Latest changes are specifically in mysql-test/main/derived.test as detailed in slack.
            Thanks, Rex ]
            Johnston Rex Johnston added a comment - - edited Please test https://github.com/MariaDB/server/tree/bb-11.7-MDEV-31466

            So before it was supported, but in a very limited fashion only - i.e. not more than one column at the time and not more than one row at the time - correct?

            CS 10.5.27 0e27351028a4888b0da271e2089bf1f847620396 (Optimized)

            10.5.27-opt>select (values(1)) as 'a', (values(2)) as 'b';
            +------+------+
            | a    | b    |
            +------+------+
            |    1 |    2 |
            +------+------+
            1 row in set (0.001 sec)
            

            Roel Roel Van de Paar added a comment - So before it was supported, but in a very limited fashion only - i.e. not more than one column at the time and not more than one row at the time - correct? CS 10.5.27 0e27351028a4888b0da271e2089bf1f847620396 (Optimized) 10.5.27-opt>select (values(1)) as 'a', (values(2)) as 'b'; +------+------+ | a | b | +------+------+ | 1 | 2 | +------+------+ 1 row in set (0.001 sec)
            Roel Roel Van de Paar made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Roel Van de Paar [ roel ]
            Johnston Rex Johnston added a comment - - edited

            The mechanism renames columns outside the query block, rather than inside. So for the block

            ( select c1 as a, c2 as b from t1 where a > 1 )
            

            in clauses within the block, we can use either c1 or a as field references, if we assign the block to a derived table

            ( select c1 as a, c2 as b from t1 where a > 1 ) dt (something1, something2)
            

            our clauses within the block need not change, but outside this block, we are now forced to use something1 or something2.
            It means we can easily rip out tables from a query and drop in derived table with the same names and not have to rewrite other parts of the query to accommodate different column names.

            Johnston Rex Johnston added a comment - - edited The mechanism renames columns outside the query block, rather than inside. So for the block ( select c1 as a, c2 as b from t1 where a > 1 ) in clauses within the block, we can use either c1 or a as field references, if we assign the block to a derived table ( select c1 as a, c2 as b from t1 where a > 1 ) dt (something1, something2) our clauses within the block need not change, but outside this block, we are now forced to use something1 or something2. It means we can easily rip out tables from a query and drop in derived table with the same names and not have to rewrite other parts of the query to accommodate different column names.
            Roel Roel Van de Paar made changes -
            serg Sergei Golubchik made changes -
            serg Sergei Golubchik made changes -
            Roel Roel Van de Paar added a comment - - edited

            Created MDEV-34941 MDEV-31466: SIGSEGV in st_select_lex_unit::rename_types_list on SELECT ... UNION

            UPDATE: retested patched branch bb-11.7-MDEV-31466 looks fine.

            Roel Roel Van de Paar added a comment - - edited Created MDEV-34941 MDEV-31466 : SIGSEGV in st_select_lex_unit::rename_types_list on SELECT ... UNION UPDATE: retested patched branch bb-11.7- MDEV-31466 looks fine.
            Roel Roel Van de Paar made changes -
            ralf.gebhardt Ralf Gebhardt made changes -
            Labels Preview_11.7

            OK to push

            Roel Roel Van de Paar added a comment - OK to push
            Roel Roel Van de Paar made changes -
            Assignee Roel Van de Paar [ roel ] Rex Johnston [ JIRAUSER52533 ]
            Roel Roel Van de Paar made changes -
            Status In Testing [ 10301 ] Stalled [ 10000 ]
            Johnston Rex Johnston made changes -
            Assignee Rex Johnston [ JIRAUSER52533 ] Igor Babaev [ igor ]
            Status Stalled [ 10000 ] In Review [ 10002 ]

            Ok, I finally approve the implementation of this task.

            igor Igor Babaev (Inactive) added a comment - Ok, I finally approve the implementation of this task.
            igor Igor Babaev (Inactive) made changes -
            Status In Review [ 10002 ] Stalled [ 10000 ]
            igor Igor Babaev (Inactive) made changes -
            Assignee Igor Babaev [ igor ] Rex Johnston [ JIRAUSER52533 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.8 [ 29921 ]
            Fix Version/s 11.7 [ 29815 ]
            serg Sergei Golubchik made changes -
            Fix Version/s 11.7 [ 29815 ]
            Fix Version/s 11.8 [ 29921 ]
            Johnston Rex Johnston made changes -
            Component/s Data Manipulation - Subquery [ 10107 ]
            Component/s Data Definition - Temporary [ 10123 ]
            Component/s Data Manipulation - Insert [ 10101 ]
            Fix Version/s 11.7.1 [ 29913 ]
            Fix Version/s 11.7 [ 29815 ]
            Resolution Fixed [ 1 ]
            Status Stalled [ 10000 ] Closed [ 6 ]
            Johnston Rex Johnston made changes -
            Fix Version/s 11.7 [ 29815 ]
            Fix Version/s 11.7.1 [ 29913 ]
            Johnston Rex Johnston made changes -
            Fix Version/s 11.7.1 [ 29913 ]
            Fix Version/s 11.7 [ 29815 ]
            serg Sergei Golubchik made changes -

            People

              Johnston Rex Johnston
              Johnston Rex Johnston
              Votes:
              0 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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