PostgreSQL jika null lalu 0

select coalesce(avg(bar), 0) from foo;
GutoTrosla