From: | "Jonathan S(dot) Katz" <jonathan(dot)katz(at)excoventures(dot)com> |
---|---|
To: | Daniele Varrazzo <daniele(dot)varrazzo(at)gmail(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:29:06 |
Message-ID: | 762C37E3-19FE-4462-B690-EFBE6ECAF29A@excoventures.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | psycopg |
On Sep 24, 2012, at 5:57 AM, Daniele Varrazzo wrote:
> On Mon, Sep 24, 2012 at 10:45 AM, Karsten Hilbert
> <Karsten(dot)Hilbert(at)gmx(dot)net> wrote:
>> On Mon, Sep 24, 2012 at 09:56:14AM +0100, Daniele Varrazzo wrote:
>>
>>> The funniest surprise I've had during the development
>>> was an error creating the object TextRange('#', '$') in the database.
>>> It should be possible as
>>>
>>>>>> ord('#'), ord('$')
>>> (35, 36)
>>>
>>> but PG insisted that "range lower bound must be less than or equal to
>>> range upper bound". Well, turns out that:
>>>
>>> postgres=# select ascii('#') < ascii('$'), '#' < '$';
>>> ?column? | ?column?
>>> ----------+----------
>>> t | f
>>> (1 row)
>>
>> This does not seem intuitive but is probably quite logical:
>>
>> While
>>
>> ascii('#') < ascii('$')
>>
>> eventually compares numerical values (35 and 36) the comparison
>>
>> '#' < '$'
>>
>> operates on characters the sorting order (<) of which
>> depends on the lcoale in use.
>
> That's right: the reason is the locale. select '#' collate "C" < '$'
> collate "C" returns true as naively expected.
>
> -- Daniele
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"
Jonathan
From | Date | Subject | |
---|---|---|---|
Next Message | Daniele Varrazzo | 2012-09-24 16:44:53 | Re: Range type adaptation implemented |
Previous Message | Daniele Varrazzo | 2012-09-24 09:57:53 | Re: Range type adaptation implemented |