[Django] #34606: RIGHT function on Oracle returns improper value when the length is zero

2 views
Skip to first unread message

Django

unread,
May 30, 2023, 3:36:36 AM5/30/23
to django-...@googlegroups.com
#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.

Reply all
Reply to author
Forward
0 new messages