Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

E0011 position-out-of-range

ORDER BY / GROUP BY position is not in the select list.

CodeNameCategoryDefault
E0011position-out-of-rangecorrectnesserror

What it reports

ORDER BY n or GROUP BY n refers to the n-th column of the select list, and the select list has fewer columns (or n is 0). This often happens when a column is removed from the select list and the positions are not updated.

Example

SELECT id, total FROM orders ORDER BY 3;
error[E0011]: ORDER BY position 3 is not in the select list
  --> q.sql:1:1
    |
  1 | SELECT id, total FROM orders ORDER BY 3;
    | ^^^^^^
    = help: The select list has 2 columns; positions count from 1

Fixed:

SELECT id, total FROM orders ORDER BY 2;

Notes

Only plain integers are positions: ORDER BY 2 + 0 is an expression. When the select list contains * over a relation whose columns are unknown, nothing is reported. Not checked for Databricks, where positions can be turned off by configuration.

Configuring

# sqlsift.toml
[rules]
position-out-of-range = "warn"   # or "off"

Or for a single line: -- sqlsift:disable E0011. The examples use the schema on the Rules page.