Opened 6 years ago

Closed 5 years ago

#29916 closed New feature (fixed)

Add lower_inc, upper_inc, lower_inf, and upper_inf range lookups

Reported by: Peter J. Farrell Owned by: Dulmandakh
Component: contrib.postgres Version: dev
Severity: Normal Keywords: lower_inf, upper_inf, lower_inc, upper_inc
Cc: Sergey Fedoseev, Srinivas Reddy Thatiparthy Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Peter J. Farrell)

Add support for following functions for Postgres range fields that are currently not supported in Django:

  • lower_inc
  • upper_inc
  • lower_inf
  • upper_inf

https://www.postgresql.org/docs/9.3/static/functions-range.html

Example usage:

MyObject.objects.filter(date_range__upper_inf=True)  # for infinity
MyObject.objects.filter(date_range__upper_inf=False)  # for not infinity

Example code: https://gist.github.com/peterfarrell/5c7b8d80319563813caba6320b568829

These can all be implemented as new ORM lookups for the Postgres range type fields so the Django ORM can gain parity with functionality available in Postgres range fields.

Change History (13)

comment:1 by Peter J. Farrell, 6 years ago

Owner: set to Peter J. Farrell

I am volunteering to make a PR to add support for these 5 functions. I will start work on a PR (including tests and documentation) if this ticket is accepted.

I have two working custom lookups (lower_inf and upper_inf) already built (see the gist linked in the main ticket). They need to add casting for different range types to improve compatibility however the concept is sound.

comment:2 by Peter J. Farrell, 6 years ago

Description: modified (diff)

comment:3 by Peter J. Farrell, 6 years ago

Description: modified (diff)

comment:4 by Tim Graham, 6 years ago

Summary: Add additional Postgres lookups to gain parity with supported range functions in PostgresAdd isempty, lower_inc, upper_inc, lower_inf, and upper_inf range lookups
Triage Stage: UnreviewedAccepted

comment:5 by Peter J. Farrell, 6 years ago

The isempty postgres function is already implemented and documented. However, lower and upper functions are implemented by as startswith and endswith which is a bit confusing unless you look at the code. So I am planning on improving the documentation to indicated which postgres function those lookups map to.

comment:6 by Peter J. Farrell, 6 years ago

Description: modified (diff)

comment:7 by Sergey Fedoseev, 6 years ago

Cc: Sergey Fedoseev added

comment:8 by Srinivas Reddy Thatiparthy, 6 years ago

Cc: Srinivas Reddy Thatiparthy added

comment:9 by Peter J. Farrell, 6 years ago

Keywords: isempty removed
Summary: Add isempty, lower_inc, upper_inc, lower_inf, and upper_inf range lookupsAdd lower_inc, upper_inc, lower_inf, and upper_inf range lookups

comment:10 by Mariusz Felisiak, 5 years ago

Has patch: set
Needs documentation: set
Owner: changed from Peter J. Farrell to Dulmandakh
Patch needs improvement: set
Version: 2.1master

comment:11 by Dulmandakh, 5 years ago

I'm not a native English speaker, so have trouble writing documentation. Please help.

comment:12 by Mariusz Felisiak, 5 years ago

Needs documentation: unset
Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

I added docs and release notes.

comment:13 by Mariusz Felisiak <felisiak.mariusz@…>, 5 years ago

Resolution: fixed
Status: assignedclosed

In 24b9f508:

Fixed #29916 -- Added lower_inc, lower_inf, upper_inc, and upper_inf lookups for RangeFields.

Co-Authored-By: Mariusz Felisiak <felisiak.mariusz@…>

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