Re: Scalar in a range (but textual not numeric) - Mailing list pgsql-sql

From Tom Lane
Subject Re: Scalar in a range (but textual not numeric)
Date
Msg-id 7219.1077748650@sss.pgh.pa.us
Whole thread Raw
In response to Re: Scalar in a range (but textual not numeric)  (Tom Lane <tgl@sss.pgh.pa.us>)
Responses Re: Scalar in a range (but textual not numeric)  (Richard Huxton <dev@archonet.com>)
List pgsql-sql
I wrote:
> try writing
>     WHERE 'ABCDE' >= pr_min AND 'ABCDE' <= pr_max
>           AND pr_min < (SELECT pr_min FROM table
>                 WHERE pr_min > 'ABCDE'
>                 ORDER BY pr_min LIMIT 1)
> The idea here is to add an upper bound on pr_min to the index scan
> conditions, so that the scan can stop short of the end of the index.

Argh, got that backwards.  What you are missing is a *lower* bound on
pr_min, and the index scan will therefore run from the start of the
index up to pr_min = 'ABCDE'.  So reverse the sense of the added test:
      AND pr_min >= (SELECT pr_min FROM table             WHERE pr_min <= 'ABCDE'             ORDER BY pr_min DESC
LIMIT1)
 
        regards, tom lane


pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: Scalar in a range (but textual not numeric)
Next
From: "Greg Sabino Mullane"
Date:
Subject: Re: Last day of month