Zero-option "case" dimensions compile but don't work
Author: igorlukaninCreated Feb 14, 2023Updated Sep 30, 2026
Describe the bug It is possible to create a dimension of the "case" type with no options in the "when" array and just the "else" statement. The data model would compile but the resulting SQL would be incorrect and wouldn't run.
To Reproduce Steps to reproduce the behavior:
- Add a dimension like this:
area: {
case: {
when: [
],
else: { label: `Unknown` }
},
type: `string`,
},- When querying, see it's compiled to the following:
SELECT
CASE
ELSE 'Unknown'
END `web_sessions__area`,
...- See the error:
Syntax error: Unexpected keyword ELSE at [3:6]Expected behavior I think that any of these two options would work:
- a dimension like this is considered incorrect and wouldn't validate/compile
- a dimension like this is considered correct and would compile to a correct SQL query (essentially becoming a string dimension)
Screenshots —
Minimally reproducible Cube Schema See above.
Version: 0.31.62
Source: cube-js/cube