Fix precedence of EXCEPT
Details
| Detail name | Value |
|---|---|
| Changelog Number | 28180 |
| Type | Bug |
| Status | Resolved |
| Affected Versions | Exasol 6.2.0, Exasol 7.0.0, Exasol 7.1.0, Exasol 8.0.0, Exasol 8.1.0 |
| Fix Versions | Exasol 2026.1.0, Exasol 2025.2.1 |
| Resolution Date | 2026-03-20 |
Description
The table operators UNION and EXCEPT have equal operator precedence while INTERSECT has higher operator precedence. Table operators with equal operator precedence are left-associative, that is they are evaluated from left to right.
In Exasol, EXCEPT had an incorrect operator precedence higher than the other operators. This can lead to queries that give wrong results.
Example
-- Setup create table A (C1 int); insert into A values (1); create table B (C1 int); insert into B values (2); create table C (C1 int); insert into C values (4); -- Q1: EXCEPT and INTERSECT -- Expected: 1 row, values (1) -- Observed: 0 rows select * from A except select * from B intersect select * from C; -- The database executes Q1 like this. -- Expected/Observed: 0 rows (select * from A except select * from B) intersect select * from C; -- Q1 should be executed like this. -- Workaround for Q1 -- Expected/Observed: 1 row, values (1) select * from A except (select * from B intersect select * from C); -- Q2: EXCEPT and UNION -- Expected: 1 row, values (2) -- Observed: 2 rows, values (1), (2) select * from A union select * from B except select * from A; -- The database executes Q2 like this. -- Expected/Observed: 2 rows, values (1), (2) select * from A union (select * from B except select * from A); -- Q2 should be executed like this. -- Workaround for Q2 -- Expected/Observed: 1 row, values (2) (select * from A union select * from B) except select * from A;
Workaround
Use brackets to choose the correct order of evaluation.
Fix
The query returns the correct results.
Changed behavior
The operator precedence of the table operator EXCEPT was incorrectly higher than INTERSECT. We changed the operator precedence to be the same as UNION.