Fixed #18247 -- Added cast to NUMERIC for Decimals on sqlite

On sqlite the SUM() of a decimal column doesn't have a NUMERIC type so
when comparing it to a string literal (which a Decimal gets converted to
in Django) it is not compared as expected.
This commit is contained in:
Michael Tänzer 2015-06-07 02:05:36 +02:00 committed by Tim Graham
parent b64c0d4d61
commit 3bbaf84d65
2 changed files with 23 additions and 0 deletions

View file

@ -507,6 +507,15 @@ class Func(Expression):
template = template or self.extra.get('template', self.template)
return template % self.extra, params
def as_sqlite(self, *args, **kwargs):
sql, params = self.as_sql(*args, **kwargs)
try:
if self.output_field.get_internal_type() == 'DecimalField':
sql = 'CAST(%s AS NUMERIC)' % sql
except FieldError:
pass
return sql, params
def copy(self):
copy = super(Func, self).copy()
copy.source_expressions = self.source_expressions[:]