[MDEV-16901] Implement an optional list of column names with the derived table name Created: 2018-08-05  Updated: 2023-11-30

Status: Open
Project: MariaDB Server
Component/s: Optimizer, Parser
Fix Version/s: None

Type: New Feature Priority: Major
Reporter: Galina Shalygina (Inactive) Assignee: Igor Babaev
Resolution: Unresolved Votes: 11
Labels: None


 Description   

<table primary> ::=
    ...
    | <derived table> [ AS ] <correlation name>
        [ <left paren> <derived column list> <right paren> ]
    ...
 
<derived column list> ::= <column name list>
 
<column name list> ::=
    <column name> [ { <comma> <column name> }... ]

SQL Standard says that with the derived table name an optional list of column names used in this derived table can also be specified. This feature is not implemented in MariaDB.

The usage of this feature:

SELECT *
FROM
(
  SELECT MAX(a), b
  FROM t1
  GROUP BY b
) AS tab(max_a, b);

The most interesting case of using this feature will be with the derived table defined with a table value constructor. In this example there is no possibility to come at 'tab' columns directly.

SELECT *
FROM
(
  VALUES ((1,1),(2,2))
) AS tab;

Using the suggested feature it becomes possible:

SELECT *
FROM
(
  VALUES ((1,1),(2,2))
) AS tab(a,b)
SELECT a FROM tab;



 Comments   
Comment by Yitzchak [ 2021-08-23 ]

Re "no possibility", you can always do:

```
SELECT *
FROM
(
SELECT NULL colA, NULL colB WHERE 0
UNION
VALUES (1,1),(2,2)
) AS tab
```

The naming the columns after the first row's value seems useless; mysql uses column_0, column_1, etc.; it would be great if that could be changed to match mysql.

Generated at Thu Feb 08 08:32:24 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.