prefer-coalesce
What it does
Section titled “What it does”Reports a call of IFNULL or NVL.
Why it matters
Section titled “Why it matters”COALESCE is in the SQL standard and works on every database. IFNULL and NVL are vendor functions, take two arguments only and may handle types differently.
To fix, write COALESCE.
Example
Section titled “Example”...select 1 union all select 2;select 1 union distinct select 2;select ifnull(a, 0), nvl(b, 0), coalesce(c, 0) from t;...select a from t left join u on t.a = u.a;...Configuration
Section titled “Configuration”sql: lint: rules: prefer-coalesce: warn # off (default), warn, errorEnabled by the presets: sql/sqlfluff.
Suppress one line with sudsy-disable-next-line prefer-coalesce 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 | CV02 |
full |