Django

Code

Ticket #10154 (new)

Opened 1 year ago

Last modified 2 months ago

allow the combination of an F expression with a timedelta

Reported by: Koen Biermans <koen.biermans@werk.belgie.be> Assigned to: nobody
Milestone: Component: Database layer (models, ORM)
Version: SVN Keywords: expressions
Cc: gt4329b@pobox.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

The proposal is to allow combining a F expression with a timedelta.

eg:

>>> longevents = Event.objects.filter(enddate__gt=F('startdate')+datetime.timedelta(days=5))

would return the events longer than 5 days.

I am attaching a first patch, which obviously needs refining.

Attachments

dateexpressions.diff (6.3 kB) - added by Koen Biermans <koen.biermans@werk.belgie.be> on 01/30/09 09:23:19.
first stab at comining expressions with timedeltas
dateexpressions_2.diff (7.0 kB) - added by Koen Biermans <koen.biermans@werk.belgie.be> on 01/31/09 14:23:01.
new patch without the leaf
10154_dateexpressions_3.diff (8.0 kB) - added by ikelly on 02/12/09 17:26:28.
Updated patch with Oracle syntax
10154_dateexpressions_4.diff (11.4 kB) - added by yourcelf on 02/03/10 12:41:06.
Updated for R12380. Support for mysql, postgres, sqlite, oracle. Includes tests and docs.

Change History

01/30/09 09:23:19 changed by Koen Biermans <koen.biermans@werk.belgie.be>

  • attachment dateexpressions.diff added.

first stab at comining expressions with timedeltas

01/30/09 14:53:54 changed by Reflejo

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

I'm mostly -1 regarding how Leaf.evaluate() is implemented. Maybe is more simple if timedelta is converted to seconds (delta.seconds + delta.day * 86400), so you don't need to do that "mods" things :-).

This way you can move representations to each backend.

01/31/09 14:23:01 changed by Koen Biermans <koen.biermans@werk.belgie.be>

  • attachment dateexpressions_2.diff added.

new patch without the leaf

01/31/09 14:26:06 changed by Koen Biermans <koen.biermans@werk.belgie.be>

  • needs_better_patch set to 1.
  • needs_docs set to 1.

You are right, we can easily do without the leaf. see new patch.

The dispatching of the nodes should be made more generic though, but I don't know which way would be best to go about that.

I have also added a few more tests.

02/12/09 17:26:28 changed by ikelly

  • attachment 10154_dateexpressions_3.diff added.

Updated patch with Oracle syntax

02/12/09 17:36:37 changed by ikelly

Suggest adding tests for timedeltas with fractional seconds. The sqlite and postgres implementations do not appear to support that at the moment.

02/26/09 14:49:07 changed by Alex

  • stage changed from Unreviewed to Accepted.

03/20/09 12:13:18 changed by yourcelf

Just added 10154_dateexpressions_4.diff, which implements and has tests for fractional seconds in sqlite and postgres, handles the case of a zero timedelta, and adds documentation.

04/09/09 12:21:43 changed by gt4329b

I'm definitely a big juicy +1 on this, as I need it right now for one of my sites

04/09/09 12:22:05 changed by gt4329b

  • cc set to gt4329b@pobox.com.

02/03/10 12:41:06 changed by yourcelf

  • attachment 10154_dateexpressions_4.diff added.

Updated for R12380. Support for mysql, postgres, sqlite, oracle. Includes tests and docs.

02/03/10 12:44:12 changed by yourcelf

Added a new patch that passes tests against trunk (R12380) for this functionality, and implements MySQL. While microseconds are implemented, I removed tests for microseconds, because it seems MySQL and SQLite don't fully implement date comparisons involving microseconds.

Also added full support for MySQL.

I did not test with Oracle as I don't have an Oracle installation to test with (this patch relies on ikelly's patch for the implementation).

02/03/10 17:37:00 changed by yourcelf

  • needs_better_patch deleted.
  • needs_docs deleted.

Can someone test oracle with this patch?

If it passes, I think this ticket is ready for checkin after review from a triager/developer.


Add/Change #10154 (allow the combination of an F expression with a timedelta)




Change Properties
Action