#34606: RIGHT function on Oracle returns improper value when the length is zero
-------------------------------------+-------------------------------------
               Reporter:  Kacper     |          Owner:  nobody
  Wolkiewicz                         |
                   Type:  Bug        |         Status:  new
              Component:  Database   |        Version:  4.0
  layer (models, ORM)                |
               Severity:  Normal     |       Keywords:  oracle right substr
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Hi
 I have found that the `RIGHT` database function on Oracle returns the
 whole string instead of empty string when the given length is 0. You can't
 explicitly give 0 to the `RIGHT` function, but it may be computed by the
 database. Basic example (you can use any model with a CharField):

 {{{#!python
 from django.db.models.functions import Right, Length

 MyModel.objects.annotate(suffix=Right("foo", Length("foo") -
 Length("foo")))
 }}}

 On PostgreSQL this will return an empty string under the field `suffix`,
 but on Oracle this will return the whole contents of the field `foo`. This
 is because Django uses the `SUBSTR` function on Oracle by multiplying the
 given length value by -1 and giving it as a `position` argument. I think
 it is not intended behavior and it should return the empty string as
 PostgreSQL does. Or at least be documented as a Note in the `Right`
 function documentation.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/34606>
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 unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701886b964b0b-80b00862-f3a2-4957-a681-60a5bf99c571-000000%40eu-central-1.amazonses.com.

Reply via email to