Wednesday, September 29, 2010

SUM(A + B) vs SUM(A) + SUM(B)

In PostgreSQL, a integer plus a null get null, so these two expressions is different not only in result but also in logic:

SELECT SUM(A + B) FROM youtable;
SELECT SUM(A) + SUM(B) FROM youtable;

You can verify this if your A or B has null value.

No comments:

Post a Comment