PostgreSQL, если null, то 0
select coalesce(avg(bar), 0) from foo;
GutoTrosla
select coalesce(avg(bar), 0) from foo;