instead 0 i am getting values -2.8421709430404e-14 in postgres code example Example: postgresql if null then 0 select coalesce(avg(bar), 0) from foo;