Re: [SQL] Scalar in a range (but textual not numeric)

2004-06-07 Thread Tom Lane
Richard Huxton [EMAIL PROTECTED] writes: Large table representing non-overlapping blocks: blocks(id int4, min varchar, max varchar) SELECT * FROM blocks WHERE 'ABCDE' BETWEEN min AND max; The estimator gets the wrong plan because it doesn't realise there's (at most) only one block that can

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-26 Thread Richard Huxton
On Wednesday 25 February 2004 22:37, Tom Lane wrote: 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

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-26 Thread Bruno Wolff III
On Thu, Feb 26, 2004 at 07:55:14 -0700, Edmund Bacon [EMAIL PROTECTED] wrote: On Wed, 2004-02-25 at 12:18, Richard Huxton wrote: As a complete aside: Is there any advantage to use varchar instead of type text? Only if there is a business rule that limits the length of the data.

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-26 Thread Edmund Bacon
On Wed, 2004-02-25 at 12:18, Richard Huxton wrote: As a complete aside: Is there any advantage to use varchar instead of type text? Thanks ---(end of broadcast)--- TIP 3: if posting/reading through Usenet, please send an appropriate

[SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Richard Huxton
Large table representing non-overlapping blocks: blocks(id int4, min varchar, max varchar) SELECT * FROM blocks WHERE 'ABCDE' BETWEEN min AND max; The estimator gets the wrong plan because it doesn't realise there's (at most) only one block that can match. Can't use any of the geometry

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Richard Huxton
On Wednesday 25 February 2004 19:18, Richard Huxton wrote: Large table representing non-overlapping blocks: blocks(id int4, min varchar, max varchar) SELECT * FROM blocks WHERE 'ABCDE' BETWEEN min AND max; The estimator gets the wrong plan because it doesn't realise there's (at most) only

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Joe Conway
Richard Huxton wrote: That's not quite the same though, because it means I need to split ABCAA..ABDBB into ABCAA..ABCZZ and ABDAA..ABDZZ but it's close enough unless someone is feeling clever this evening. Would (a series of) partial indexes help? Joe ---(end of

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Richard Huxton
On Wednesday 25 February 2004 20:56, Joe Conway wrote: Richard Huxton wrote: That's not quite the same though, because it means I need to split ABCAA..ABDBB into ABCAA..ABCZZ and ABDAA..ABDZZ but it's close enough unless someone is feeling clever this evening. Would (a series of) partial

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Richard Huxton
On Wednesday 25 February 2004 21:32, Tom Lane wrote: Richard Huxton [EMAIL PROTECTED] writes: Large table representing non-overlapping blocks: blocks(id int4, min varchar, max varchar) SELECT * FROM blocks WHERE 'ABCDE' BETWEEN min AND max; The estimator gets the wrong plan because it

Re: [SQL] Scalar in a range (but textual not numeric)

2004-02-25 Thread Tom Lane
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