No Settled Transactions is 0, not Null

Christopher Vollick created

Unexpectedly this doesn't return either no columns or a column with a
value of 0, but instead a column with no value...

Change summary

lib/trust_level_repo.rb | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

Detailed changes

lib/trust_level_repo.rb 🔗

@@ -27,7 +27,7 @@ protected
 
 	def fetch_settled_amount(customer_id)
 		db.query_one(<<~SQL, customer_id, default: {})
-			SELECT SUM(amount) AS settled_amount FROM transactions
+			SELECT COALESCE(SUM(amount), 0) AS settled_amount FROM transactions
 			WHERE customer_id=$1 AND settled_after < LOCALTIMESTAMP AND amount > 0
 		SQL
 	end