Opened 14 years ago

Closed 14 years ago

#14569 closed (wontfix)

Date field expression raw query returns unicode instead of datetime object in sqlite

Reported by: Robin Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords: raw query date sqlite postgresql
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Using sqlite

>>> m = MyModel.objects.raw('select id,max(date_added) as d from app_modelname group by id')
>>> m[0].d
u'2010-10-26 04:11:33.123513'

Whereas with postgresql

>>> m[0].d
datetime.datetime(2010, 10, 26, 4, 11, 33)

I believe the result returning a datetime object by postgresql is correct, whereas sqlite is not.

Change History (2)

comment:1 by Daniel F Moisset, 14 years ago

The problem here is that you're using an expression, not a column name. The raw queryset maps all columns to the correct fields, but if you use arbitrary expressions it lets the db value through... and sqlite has no datetime values, just numbers and unicode strings.

comment:2 by Ramiro Morales, 14 years ago

Resolution: wontfix
Status: newclosed
Summary: Raw query for date field returns unicode instead of datetime object in sqliteDate field expression raw query returns unicode instead of datetime object in sqlite

So, unfortunately we can't fix this in Django because that means it would need to interpret all raw SQL queries and deduce the correct data type of the query result. Closing as wontfix

Note: See TracTickets for help on using tickets.
Back to Top