On Sun, Mar 10, 2013 at 1:44 PM, Petite Abeille
<[email protected]> wrote:
>
> On Mar 10, 2013, at 8:28 PM, Aymeric Augustin
> <[email protected]> wrote:
>
>> Django does this already:
>> https://github.com/django/django/blob/master/django/db/backends/oracle/base.py#L548-L555
>
> Perfect.
>
> In the case of #20015, the issue is the other way round… the literal '2008%'
> cannot be implicitly converted to a date. Implicit conversion always go to
> the narrowest type. You would be better off converting it explicitly, e.g.
> to_date( '2008', 'YYYY' ) or such. Then the query become date >= to_date(
> '2008', 'YYYY' ). Alternatively, you could convert the date column to a
> varchar: to_char( date ) like '2008%'…
The lookup requested by the user in this somewhat obscure scenario is
fundamentally a string lookup, though. For example, this alternate
lookup is entirely legitimate as far as Django is concerned:
MyModel.objects.filter(somedate__startswith='200')
Which could match anything with the year 200 but more likely is
intended as a decade match, matching any date in the 200X decade. To
support that, the query would have to become something like "somedate
between to_date('2000', 'YYYY') and to_date('2009-12-31
23:59:59.999999', 'YYYY-MM-DD HH:MM:SS.FFFFFF')"
And there would have to be different conversions for other possible
substring lookups. Generating those kinds of queries from Django
string lookups would be a hairy mess.
Digging into the code a bit further, I see that the postgresql backend
accomplishes this by tacking '::text' onto the end of the field name
when the lookup is a string-based lookup like startswith. Oracle
could probably do something similar with the TO_CHAR function.
--
You received this message because you are subscribed to the Google Groups
"Django developers" 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].
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.