Re: Range type adaptation implemented

From: Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(dot)com>
To: "Jonathan S(dot) Katz" <jonathan(dot)katz(at)excoventures(dot)com>
Cc: Karsten Hilbert <Karsten(dot)Hilbert(at)gmx(dot)net>, psycopg(at)postgresql(dot)org
Subject: Re: Range type adaptation implemented
Date: 2012-09-24 16:44:53
Message-ID: CA+mi_8Ze2Fr6gc1qKYxK4MFO2URQQbL8sU4DUvdb8WCxQy6CiA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: psycopg

On Mon, Sep 24, 2012 at 5:29 PM, Jonathan S. Katz
<jonathan(dot)katz(at)excoventures(dot)com> wrote:

> With that said, referencing this line:
>
> https://github.com/dvarrazzo/psycopg/blob/range-type/lib/_range.py#L135
>
> Because those sets of operators are supposed on the Postgres side, perhaps
> we could provide an error message indicating that? That way if someone
> needs to look at the comparisons between ranges they know the database
> operators. So maybe:
>
> "Range objects cannot be ordered - please refer to the PostgreSQL
> documentation to perform this operation in the database"

Yeah, we could improve that message. The important thing was to
disallow r1 < r2 at all, because the Python "object" type by default
implements these operators as pointer comparison: if an user gets a
result True or False out of ranges comparison he may think the
operation is allowed and returns something meaningful...

I've actually not found any object that *doesn't compare* in Python,
so I don't know exactly how to deal with it. There are objects with
partial ordering around (e.g. sets) but they return False if not
comparable.

>>> set('a') < set('b')
False
>>> set('a') > set('b')
False

We could return False to any comparison but still it's not like "you
cannot do that, mate". Anybody knows an example of unorderable object
in Python? Is there anything more appropriate than throwing TypeError?

-- Daniele

In response to

Responses

Browse psycopg by date

  From Date Subject
Next Message Jacob Kaplan-Moss 2012-09-24 17:36:27 Re: Range type adaptation implemented
Previous Message Jonathan S. Katz 2012-09-24 16:29:06 Re: Range type adaptation implemented