how to add if value null then 0 in postgres code example Example: postgresql if null then 0 select coalesce(avg(bar), 0) from foo;