if is null postgresql code example Example 1: postgresql if null then 0 select coalesce(avg(bar), 0) from foo; Example 2: ifnull postgres SELECT coalesce(column, 1)