#36078: Document that Postgres normalizes a range field with no points normalizes
to empty
--------------------------------------+------------------------------------
Reporter: Mapiarz | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: contrib.postgres | Version: 4.2
Severity: Normal | Resolution:
Keywords: postgres | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Daniele Varrazzo):
> I agree. There should be an explicit warning about this. It's really
easy to be caught of guard by this and lose data.
You are already losing data, because if you are calling
`DateTimeTZRange('2025-01-01', '2025-01-31')` to mean the whole month of
January you are losing a day, because the default bounds are `[)` so the
31st is not in the range, the same way that 4 is not in the `[4,4)` range.
The data loss comes from using the wrong bounds, not from the
normalization rules, which are the same whether implemented by Python or
by Postgres.
In the above example, `DateTimeTZRange(now, now, '[]')` might have been
what you wanted.
I have left a response on the psycopg tracker. I am -0.5 to introduce
normalization in Python, but, regardless from that, I don't think it would
have resulted in any difference w.r.t. the issue explained here. If we had
returned what the OP expected to receive it would have meant we have a bug
as Psycopg normalization would disagree with Postgres one.
--
Ticket URL: <
https://code.djangoproject.com/ticket/36078#comment:6>