rules repository

G-3180

🆓
Warning

Always specify column names instead of positional references in ORDER BY clauses.

Reason

If you change your select list afterwards the order by will still work but order your rows differently, when not changing the positional number. Furthermore, it is not comfortable to the readers of the code, if they have to count the columns in the select list to know the way the result is ordered.

Example

Non-Compliant Example

select upper(first_name)
      ,last_name
      ,salary
      ,hire_date
  from employees
 order by 4,1,3;
Issues
LineColumnMessage
611Positional reference 4 in ORDER BY clause.
613Positional reference 1 in ORDER BY clause.
615Positional reference 3 in ORDER BY clause.

Compliant Solution - ★★★★★

select upper(first_name) as first_name
      ,last_name
      ,salary
      ,hire_date
  from employees
 order by hire_date
      ,first_name
      ,salary;

Parameters

Use parameters to customize the rule to your needs.

ParameterDescriptionDefault Value
DisableAllQuickFixComma-separated ist of rules for which a quick fix should not be applied to all the problems in a file.Core G-3130

References