#2443: Add IntervalField to database models
-------------------------------------+-------------------------------------
               Reporter:             |          Owner:  Adys
  ben.tucker@…                       |         Status:  new
                   Type:  New        |      Component:  Database layer
  feature                            |  (models, ORM)
              Milestone:             |       Severity:  Normal
                Version:  SVN        |       Keywords:  IntervalField
             Resolution:             |  interval duration DurationField
           Triage Stage:  Accepted   |  feature
    Needs documentation:  0          |      Has patch:  1
Patch needs improvement:  1          |    Needs tests:  1
                  UI/UX:  1          |  Easy pickings:  0
-------------------------------------+-------------------------------------

Comment (by jpaulett):

 Karen,

 While Python does provide the timedelta class, there is no common SQL
 implementation for storing that object in the database.  PostgreSQL does
 provide the INTERVAL data type, MySQL and SQLite do not have any interval
 data type (I am not sure about Oracle, MSSQL, etc.).

 Luckily Django makes it relatively simple to create
 [https://docs.djangoproject.com/en/dev/howto/custom-model-fields/ custom
 model fields].  If you are willing to be PostgreSQL-specific, you could
 store timedeltas as INTERVALs (I believe the psycopg driver handles the
 conversion for you).

 You could also convievably pickle the timedelta instance and store that
 blob in the database.  This approach breaks the sorting semantics,
 potentially corrupts the data across Python versions, and is completely
 opaque from a pure database perspective.

 Another approach is to store the data in the database as a BIGINT.  This
 approach has the advantage of working across databases and retains the the
 expected sorting semantics.  The downside to this approach from a pure
 database perspective, is that you now must know the function to convert
 from a BIGINT into an interval.  Based upon the patches included in this
 ticket, myself and several other developers created [http://django-
 durationfield.readthedocs.org/ django-durationfield]. One advantage of
 being a standalone app as opposed to being in core is that we can release
 new features & bug fixes without having to wait for a major Django point
 release.

 I do not mean to speak for the core developers, but since there is no
 ideal solution and since using a standalone app is extremely easy, I doubt
 we will see this feature included in core anytime soon.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/2443#comment:50>
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 post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/django-updates?hl=en.

Reply via email to