#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 do not understand why psycopg opted out of normalizing the value to
empty, just like postgres does. I have raised this issue here:
https://github.com/psycopg/psycopg/discussions/993
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>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/django-updates/0107019460e819e2-ff117431-6234-40dd-9799-d6c2e167f8ef-000000%40eu-central-1.amazonses.com.