Postgresql turn null into zero

maverick picture maverick · Sep 17, 2011 · Viewed 54.6k times · Source

Possible Duplicate:
SELECT max(x) is returning null; how can I make it return 0?

When I execute

select max(column) from mytable;

and my table has no rows, it returns null. How can I amend this select statement so it will return zero?

Answer

Mark Byers picture Mark Byers · Sep 17, 2011
select coalesce(max(column), 0) from mytable;