#36845: Allow negative index in Left() for PostgreSQL
-------------------------------------+-------------------------------------
Reporter: Christopher | Type: New
Covington | feature
Status: new | Component: Database
| layer (models, ORM)
Version: 6.0 | Severity: Normal
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
PostgreSQL has supported negative indices since v9.1
https://www.postgresql.org/docs/9.1/functions-string.html as right side
trim length--just like Python string slicing.
Targeting the check and ValueError in `Left.__init__()` more precisely
will enable straightforward translation of a common string manipulation
pattern from Python:
`field[:-3]`
to Django ORM for PostgreSQL:
`Left('field', -3)`
For other databases I would propose initially carrying forward the non-
negative requirement. If there's interest, a Python implementation of
negative index (right side trim length) support, or something cleverer,
could follow up as separate discussion and work.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36845>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.