# Model.sum returns nil when no rows are selected. Intentional?

**URL:** <https://discuss.rubyonrails.org/t/model-sum-returns-nil-when-no-rows-are-selected-intentional/834>\
**Category:** rubyonrails-core\
**Created:** [August 31, 2006, 6:39am UTC](https://discuss.rubyonrails.org/t/model-sum-returns-nil-when-no-rows-are-selected-intentional/834 "2006-08-31T06:39:04Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_James](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mark\_James](https://discuss.rubyonrails.org/u/Mark_James)\
**Post date:** [August 31, 2006, 6:39am UTC](https://discuss.rubyonrails.org/t/model-sum-returns-nil-when-no-rows-are-selected-intentional/834/1 "2006-08-31T06:39:04Z")

</div>

Is it intended that the AR sum method return nil rather than 0 (int) or 0.0 (float) when no rows match the conditions? This is the result I get using MySQL.

I can't find any mention of this issue in either Trac or the mailing list archives, so I'll make up a patch if there's confirmation this is not the desired behaviour.
