union-distinct
What it does
Section titled “What it does”Reports a UNION that names neither DISTINCT nor ALL.
Why it matters
Section titled “Why it matters”UNION removes duplicates, which costs a sort or a hash, and UNION ALL does not. Without a keyword a reader cannot tell whether the removal is wanted, or whether ALL was forgotten.
To fix, write UNION DISTINCT or UNION ALL.
Example
Section titled “Example”select 1 union select 2;select 1 union all select 2;select 1 union distinct select 2;...Configuration
Section titled “Configuration”sql: lint: rules: union-distinct: warn # off, warn (default), errorEnabled by the presets: sql/sqlfluff.
Suppress one line with sudsy-disable-next-line union-distinct in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| sqlfluff | AM02 |
full |