Re: Strange behaviors with ranges

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Jean-Christophe Boggio <postgresql(at)thefreecat(dot)org>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Strange behaviors with ranges
Date: 2024-08-27 17:37:17
Message-ID: 572cc9d2-a981-4f0e-802a-69515dac1722@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/27/24 10:29 AM, Jean-Christophe Boggio wrote:
> Hello,
>
> I have 2 very confusing behaviors when using ranges.
>
> It all started with this query:
>
>     WITH rangespaliers AS (
>         SELECT numrange( qtep1+1   , qtep2,  '[]') AS rangep FROM
> paliers JOIN tmp_limitcontrats USING(idcontrat)
> --        SELECT numrange( qtep1+1   , qtep2,  '[]') AS rangep FROM
> paliers WHERE idcontrat=1003
>     )
>     ,rangespaliers2 AS (
>         select *
>         FROM rangespaliers
>         WHERE rangep <> NUMRANGE(NULL, NULL) -- ERROR IS HERE
>     )
>     select * from rangespaliers2;
>
> When I run this query, I get the error "Range lower bound must be less
> than or equal to range upper bound".
>
> (a) If I comment out the line marked "ERROR IS HERE", I don't have an
> error (but I'm missing the filter of course).
>
> (b) Also, if I uncomment line 3 and comment out line 2, I get the
> correct behavior. Very strange thing is that tmp_limitcontrats has only
> one row which contains "idcontrat=1003".

What does:

SELECT numrange( qtep1+1 , qtep2, '[]') AS rangep FROM paliers WHERE
idcontrat=1003

return?

>
> This fails on PG 16.4 and 15.7
>
> Thanks a lot for your enlightenment.
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Jean-Christophe Boggio 2024-08-27 17:50:30 Re: Strange behaviors with ranges
Previous Message Jean-Christophe Boggio 2024-08-27 17:29:16 Strange behaviors with ranges