This project is archived and is in readonly mode.

#163 ✓invalid
Psycopg website

Range types doesn't support infinity [now,infinity)

Reported by Psycopg website | May 24th, 2013 @ 07:12 AM

Submitted by: David Turon

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

    Daniele Varrazzo May 24th, 2013 @ 10:27 AM

    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:

    1. 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.

    2. 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

    Daniele Varrazzo June 18th, 2013 @ 02:06 PM

    • State changed from “new” to “invalid”

    I've added some docs to explain how to map date.max to infinity

    the default adapter cannot be changed for backward compatibility reason. You can use a customized adapter in your application.

  • Alex Morega

    Alex Morega October 21st, 2013 @ 01:05 PM

    InfDateAdapter.getquoted should 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 with b"" literals.

  • Daniele Varrazzo

    Daniele Varrazzo October 21st, 2013 @ 01:18 PM

    Thank you for the tip, will fix the docs.

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="">the new tracker</a>.
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.

Shared Ticket Bins