Django

Code

Ticket #5365 (closed: duplicate)

Opened 1 year ago

Last modified 1 year ago

sqlite3+DateField: field__year doesn't work.

Reported by: Jakub Wilk <django@icomputing.pl> Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: qs-rf
Cc: Triage Stage: Unreviewed
Has patch: 0 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

With DATABASE_ENGINE = 'sqlite3' and the following foo/models.py:

from django.db import models

class Foo(models.Model):
        date = models.DateField()

I try:

>>> from datetime import date
>>> from foo.models import Foo
Foo(None, date(2007, 1, 1)).save()
>>> Foo.objects.all()
[<Foo: Foo object>]
>>> Foo.objects.filter(date__range = (date(2007, 1, 1), date(2007, 12, 31)))
[<Foo: Foo object>]
>>> Foo.objects.filter(date__year = 2007)
[]

Attachments

Change History

(follow-up: ↓ 2 ) 09/08/07 15:04:26 changed by mattmcc

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

The query does work, however it appears that SQLite is performing an exclusive BETWEEN rather than an inclusive one. This is inconsistent with other DB systems, and is possibly a SQLite bug.

(in reply to: ↑ 1 ) 09/08/07 15:42:47 changed by Jakub Wilk <django@icomputing.pl>

Replying to mattmcc:

The query does work, however it appears that SQLite is performing an exclusive BETWEEN rather than an inclusive one.

Nope, this is not the case. date__range also uses a BETWEEN expression but it works fine. The problem is that SQLite doesn't have a real date/datetime type.

sqlite> SELECT date('2007-01-01');
2007-01-01
sqlite> SELECT datetime('2007-01-01');
2007-01-01 00:00:00
sqlite> SELECT 1 WHERE date('2007-01-01') > date('2007-01-01');
sqlite> SELECT 1 WHERE datetime('2007-01-01') > date('2007-01-01');
1

09/13/07 16:45:41 changed by mtredinnick

  • keywords set to qs-rf.

09/16/07 17:05:55 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to duplicate.

Closing in favor of #3689, which has patches.


Add/Change #5365 (sqlite3+DateField: field__year doesn't work.)




Change Properties
Action