[Answered ]-Django PostgreSQL IntegerRangeField and update_or_create

2đź‘Ť

âś…

Unfortunately, this is “as designed”. Putting together

Regardless of the bounds specified when saving the data, PostgreSQL
always returns a range in a canonical form that includes the lower
bound and excludes the upper bound; that is [).

and

-- includes no points (and will be normalized to 'empty')
SELECT '[4,4)'::int4range;

(from https://www.postgresql.org/docs/9.3/static/rangetypes.html)

You are out of luck. There is, however, a feature request for this, https://code.djangoproject.com/ticket/27147.

Fwiw, psycopg2 supports all range bounds types.

Options?

  1. One off custom sql (yuck)
  2. Implement the Django feature request and submit a PR
  3. Just use 2 int columns (fastest)
👤rm -rf

Leave a comment