NPE Rewrite
Copyright © 2024 PawSQL
Problem Definition
NPE (Null Pointer Exception) issues in SQL refer to cases where aggregate functions like SUM, AVG return NULL when the aggregated column is all NULL, which can then cause null pointer exceptions in subsequent program logic.
select sum(t.b) from (values row(1,null)) as t(a,b);
This can be avoided by using:
SELECT IFNULL(SUM(t.b), 0) from (values row(1,null)) as t(a,b);