I wondering whether it really makes sense to have the database do these calculations or whether it would be better (for consistency) to have them all happen in Python using the function I suggested (in another comment) we write?