Opened 6 years ago

Last modified 5 years ago

#29916 closed New feature

Add isempty, lower_inc, upper_inc, lower_inf, and upper_inf range lookups — at Version 6

Reported by: Peter J. Farrell Owned by: Peter J. Farrell
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 (6)

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)
Note: See TracTickets for help on using tickets.
Back to Top