Other than coalesce(col1, 0) + coalesce(col2, 0)
is there any built in shorthand function, like least
, that will let me do null safe addition?
Question posted in PostgreSQL
The official documentation can be found here.
The official documentation can be found here.
2
Answers
The is nothing built in, but you can create your own:
This uses the fact that
sum()
ignores NULL values.That’s just
coalesce(col1+col2, col1, col2, 0)
.