Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

There was a problem

You must be a member of this account.

This project is archived and is in readonly mode.

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

#163

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")

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

State: invalid
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    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:

    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.

    May 24th, 2013 @ 10:27 AM

  2. Daniele Varrazzo
    Daniele Varrazzo
    • 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.

    June 18th, 2013 @ 02:06 PM

  3. Alex Morega
    Alex Morega

    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.

    October 21st, 2013 @ 01:05 PM

  4. Daniele Varrazzo
    Daniele Varrazzo

    Thank you for the tip, will fix the docs.

    October 21st, 2013 @ 01:18 PM