mirror of
https://github.com/django/django.git
synced 2025-06-05 11:39:13 +00:00
[1.8.x] Fixed #24925 -- Document using Coalesce on MySQL
Add warning for using Coalesce with python values on MySQL and document workaround. Backport of 14dead04acf4ac877d0f4025f142fe9e872ce8ac from master
This commit is contained in:
parent
2aa65460d5
commit
8d33889422
@ -55,6 +55,17 @@ Usage examples::
|
|||||||
>>> print(aggregated['combined_age_default'])
|
>>> print(aggregated['combined_age_default'])
|
||||||
None
|
None
|
||||||
|
|
||||||
|
.. warning::
|
||||||
|
|
||||||
|
A python value passed to ``Coalesce`` on MySQL may be converted to an
|
||||||
|
incorrect type unless explicitly cast to the correct database type:
|
||||||
|
|
||||||
|
>>> from django.db.models.expressions import RawSQL
|
||||||
|
>>> from django.utils import timezone
|
||||||
|
>>> now = timezone.now()
|
||||||
|
>>> now_sql = RawSQL("cast(%s as datetime)", (now,))
|
||||||
|
>>> Coalesce('updated', now_sql)
|
||||||
|
|
||||||
Concat
|
Concat
|
||||||
------
|
------
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user