Skip to content

prefer-coalesce

SQLstyleno fixdefault: offsql/sqlfluff

Reports a call of IFNULL or NVL.

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.

Reported
...
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;
...
sql:
lint:
rules:
prefer-coalesce: warn # off (default), warn, error

Enabled by the presets: sql/sqlfluff.

Suppress one line with sudsy-disable-next-line prefer-coalesce in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
sqlfluff CV02 full