Since count()
never returns NULL
(unlike other aggregate functions), you only have to catch the 0
case (which is the only problematic case anyway). So, your query simplified:
CASE count(column_name)
WHEN 0 THEN 1
ELSE count(column_name)
END
Or simpler, yet, with NULLIF()
, like Yuriy provided.
Quoting the manual about aggregate functions:
It should be noted that except for
count
, these functions return a null value when no rows are selected.