Opened 32 hours ago

Last modified 11 hours ago

#36845 assigned New feature

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: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes 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 (2)

comment:1 by Moksha Choksi, 30 hours ago

Owner: set to Moksha Choksi
Status: newassigned

comment:2 by Moksha Choksi, 11 hours ago

Has patch: set
Note: See TracTickets for help on using tickets.
Back to Top