﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29845	Casting to DecimalField causes MySQL/MariaDB SQL syntax error	Ronny Vedrilla	Mariusz Felisiak	"When I cast a FloatField to Decimal, I get an error from MySQL.

Seen in django 1.11.16 on MariaDB.

Model:
{{{
class MyModel(models.Model):
    floatfield = models.FloatField()
    decimalfield = models.DecimalField(decimal_places=2, max_digits=12)
}}}

Query:
{{{
MyModel.objects.all().annotate(
    floatfield_decimal=Cast('floatfield', DecimalField(max_digits=8, decimal_places=2))).aggregate(
    revenue=Sum(F('floatfield_decimal') * F('decimalfield'))
)['revenue']
}}}

Then I see this error:
{{{
{ProgrammingError}(1064, ""You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'numeric(8, 2)) AS `floatfield_decimal`, `myclass`.`decimalfield' at line 1"")
}}}

I guess the `numeric` should be `Decimal`... It's not possible to examine the query further from the debugger.
"	Bug	closed	Database layer (models, ORM)	1.11	Normal	fixed			Ready for checkin	1	0	0	0	0	0
