Wrong column names in UNION ALL
Details
| Detail name | Value |
|---|---|
| Changelog Number | 11195 |
| Type | Bug |
| Status | Resolved |
| Affected Versions | Exasol 6.1.0, EXASOL 6.0.10, Exasol 6.2.0, Exasol 7.0.0 |
| Fix Versions | Exasol 7.1.0, Exasol 7.0.11 |
| Resolution Date | 2021-07-16 |
Description
Statements using UNION or UNION ALL may ignore column aliases in some cases.
Preparation
CREATE TABLE table_one (A VARCHAR(2000)); CREATE TABLE table_two (B VARCHAR(2000));
Example
select A as C from table_one UNION ALL select B as C from table_two;
Shows column name A instead of C
Workaround
You can wrap the UNION ALL statement in a subselect with a column alias:
select A as C from ( SELECT A FROM table_one UNION ALL SELECT B FROM table_two );
Fix
UNION and UNION ALL will always respect column aliases