Opened 3 weeks ago
Closed 3 weeks ago
#36845 closed New feature (needsnewfeatureprocess)
Allow negative index in Left() for PostgreSQL
| Reported by: | Christopher Covington | Owned by: | Moksha Choksi |
|---|---|---|---|
| Component: | Database layer (models, ORM) | Version: | 6.0 |
| Severity: | Normal | Keywords: | |
| Cc: | Christopher Covington | Triage Stage: | Unreviewed |
| Has patch: | no | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
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.
Change History (3)
comment:1 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:2 by , 3 weeks ago
| Has patch: | set |
|---|
comment:3 by , 3 weeks ago
| Easy pickings: | unset |
|---|---|
| Has patch: | unset |
| Resolution: | → needsnewfeatureprocess |
| Status: | assigned → closed |
Hi, thanks for the idea. It would help to know what advantage this would provide over using
Right(). The best place to have this discussion would be on the new features board at django/new-features.