Skip to content

fix(sql): cannot order by columns with purely numeric names#5435

Merged
bluestreak01 merged 8 commits intomasterfrom
nw_order_by_numeric
Mar 5, 2025
Merged

fix(sql): cannot order by columns with purely numeric names#5435
bluestreak01 merged 8 commits intomasterfrom
nw_order_by_numeric

Conversation

@nwoolmer
Copy link
Copy Markdown
Contributor

@nwoolmer nwoolmer commented Mar 3, 2025

Fixes #5405
Related to #5408

rewriteOrderByPosition handles positional order by queries i.e ORDER BY 1, 2.

There was a prior issue, where a column name that started with a number would throw a spurious error, despite being a valid column name.

This fixes an issue where a purely numeric named column would be interpreted as a positional index, and therefore error as out of range.

Now, the behaviour is that if the order by column is a number, and out of range, it will then be checked for a matching column name. If there is one, it will ignore it in rewriteOrderByPosition and let it continue. If the position is ambiguous (i.e there is both a position and a matching name), it would order based on the position.

@nwoolmer nwoolmer added Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution labels Mar 3, 2025
@glasstiger
Copy link
Copy Markdown
Contributor

[PR Coverage check]

😍 pass : 5 / 5 (100.00%)

file detail

path covered line new line coverage
🔵 io/questdb/griffin/SqlOptimiser.java 5 5 100.00%

@bluestreak01 bluestreak01 merged commit a20620c into master Mar 5, 2025
37 checks passed
@bluestreak01 bluestreak01 deleted the nw_order_by_numeric branch March 5, 2025 17:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug Incorrect or unexpected behavior SQL Issues or changes relating to SQL execution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cannot order by columns with numeric names

4 participants