This project is archived and is in readonly mode.
Range types doesn't support infinity [now,infinity)
-
Daniele Varrazzo
Python dates don't support infinity, so the value is mapped on maxdate, and of course the mapping is not bidirectional. It's a known shortcoming of the dates mapping, it doesn't affect the ranges only.
You have two solutions:
-
if you don't need the values of the range in python but are using the range only as a key to fetch/store records you may create a text range leaving the ranges unparsed.
-
if your database stores infinity but not maxdate you can create a datetime adapter mapping python maxdate on postgres infinity and build a range on it.
Both objects are easy to implement and use. Let me know if you need a hand with them.
-
-
Daniele Varrazzo
- State changed from new to invalid
I've added some docs to explain how to map date.max to infinity
- http://initd.org/psycopg/docs/extras.html#psycopg2.extras.DateRange
- http://initd.org/psycopg/docs/usage.html#infinite-dates-handling
the default adapter cannot be changed for backward compatibility reason. You can use a customized adapter in your application.
-
Alex Morega
InfDateAdapter.getquotedshould return a bytestring in Python 3, but this is not obvious from the documentation, and the stack trace is kind of cryptic. I think people unfamiliar with psycopg2 adapters would benefit from writing the example withb""literals. -
Daniele Varrazzo
Thank you for the tip, will fix the docs.