#26824: MySQL query with CONVERT_TZ is not properly formated
-------------------------------------+-------------------------------------
     Reporter:  truhlik              |                    Owner:  nobody
         Type:  Bug                  |                   Status:  new
    Component:  Database layer       |                  Version:  1.9
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:
     Keywords:  mysql, timezone      |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by truhlik):

 Using Mysql: 5.5.49-0+deb8u1 - (Debian)
 MySQL timezone definitions have been loaded properly.

 Strange behavior. I pass all 6 tests in the suite, which you point. But
 when I try the single SQL query, the Error appears.

 I modified the code a little to see the query which Django produce.
 {{{
     ...
         with self.settings(TIME_ZONE='UTC'):
             # But in UTC, the __date only matches one of them.
             q  = DateTimeModel.objects.filter(dt__date=d)
             print q.query
 self.assertQuerysetEqual(DateTimeModel.objects.filter(dt__date=d),
 [repr(m1)])
 }}}

 and the output is this:
 {{{
 Using existing test database for alias 'default'...
 .sSELECT `payments_datetimemodel`.`id`, `payments_datetimemodel`.`d`,
 `payments_datetimemodel`.`dt`, `payments_datetimemodel`.`t` FROM
 `payments_datetimemodel` WHERE
 DATE(CONVERT_TZ(`payments_datetimemodel`.`dt`, 'UTC', UTC)) = 2014-03-12
 ....
 ----------------------------------------------------------------------
 Ran 6 tests in 0.734s

 OK (skipped=1)
 }}}

 Then trying to use the same query (without quotes) directly in mysql
 client.

 {{{
 mysql> SELECT `payments_datetimemodel`.`id`, `payments_datetimemodel`.`d`,
 `payments_datetimemodel`.`dt`, `payments_datetimemodel`.`t` FROM
 `payments_datetimemodel` WHERE
 DATE(CONVERT_TZ(`payments_datetimemodel`.`dt`, 'UTC', UTC)) = 2014-03-12;
 ERROR 1054 (42S22): Unknown column 'UTC' in 'where clause'
 }}}

 and with quotes:

 {{{
 mysql> SELECT `payments_datetimemodel`.`id`, `payments_datetimemodel`.`d`,
 `payments_datetimemodel`.`dt`, `payments_datetimemodel`.`t` FROM
 `payments_datetimemodel` WHERE
 DATE(CONVERT_TZ(`payments_datetimemodel`.`dt`, 'UTC', 'UTC')) =
 2014-03-12;
 Empty set (0.00 sec)
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26824#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.11b4eb5c28aa9a210b6f1aba524ba1a7%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to