This project is archived and is in readonly mode.
Range types doesn't support infinity [now,infinity)
Reported by Psycopg website | 2013-05-24 07:12:34 UTC
Submitted by: David Turon
Hi,
if I get from database range for example:
["2013-05-23 14:31:52.892896+02",infinity)
and then insert back to db
["2013-05-23 14:31:52.892896+02","9999-12-31 23:59:59.999999+01")
for example UPDATE updated 0 rows because
["2013-05-23 14:31:52.892896+02",infinity)!=["2013-05-23
14:31:52.892896+02","9999-12-31 23:59:59.999999+01")
Comments and changes to this ticket
-

Daniele Varrazzo 2013-05-24 10:27:57 UTC
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 2013-06-18 14:06:33 UTC
- 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 2013-10-21 13:05:01 UTC
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. -

Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
WARNING: the informations in this tracker are archived. Please submit new tickets or comments to the new tracker.
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.