user1934212 user1934212 - 24 days ago 10
SQL Question

Replacing empty integer cells with 0 in postgreSQL

I have a view

matches_view


returning the following:

id | name | wins | losses | matches
----+----------------+------+--------+---------
2 | Peter | 1 | 2 | 3
1 | Kevin | 3 | 1 | 4
3 | John | | 1 |


How can I replace the empty columns in the last row with 0s in postgreSQL?

Answer

You can use COALESCE(<expression>, 0) for numeric columns in any case.