Re: [GENERAL] Regex query not using index

2008-02-24 Thread Alban Hertroys
On Feb 20, 2008, at 5:51 PM, Postgres User wrote: Now to end my fixation, one last item. What about the case of a null or empty param value- is there a way to assign a condition value that Postgres will ignore when processing the query? This syntax results in a seq scan: WHERE fielda = Coale

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Postgres User
Tom, I was looking for another approach but didn't come across that array syntax in my searches (perhaps because it's newer. Thanks for a solution. Now to end my fixation, one last item. What about the case of a null or empty param value- is there a way to assign a condition value that Postgres

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Tom Lane
"Postgres User" <[EMAIL PROTECTED]> writes: > My users are developers and the goal was to accept a simple > comma-delimited list of string values as a function's input parameter. > The function would then parse this input param into a valid regex > expression. Why are you fixated on this being a

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Postgres User
Tino, My users are developers and the goal was to accept a simple comma-delimited list of string values as a function's input parameter. The function would then parse this input param into a valid regex expression. I was trying to write a function that lets me avoid using Execute and instead wr

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Tino Wildenhain
Postgres User wrote: im trying to allow the client to pass a varchar param into my function, and want to avoid any parsing of the parameter inside the function, or code to build a sql string. if the function can use this code, it will be compiled and optimized (unlike a dynamic sql stirng) sele

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Martijn van Oosterhout
On Wed, Feb 20, 2008 at 12:56:54AM -0800, Postgres User wrote: > a final question: why does this syntax do a seq scan + filter: > > select * from tablea where fielda = fielda -or- select * from > tablea where fielda in (fielda) > > while this syntax results in no filter, seq scan only > > sel

Re: [GENERAL] Regex query not using index

2008-02-20 Thread Postgres User
a final question: why does this syntax do a seq scan + filter: select * from tablea where fielda = fielda -or- select * from tablea where fielda in (fielda) while this syntax results in no filter, seq scan only select * from tablea where 1 = 1 it seems that both where clauses should be ignor

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Chris
Postgres User wrote: by the way, your example works fine unless it's a null value or empty string unfortunately, postgres isn't smart enough to know that the when p_param below is null, that the WHERE condition can be ignored select * from table where name in (Coalesce(p_param, name)) which is

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
by the way, your example works fine unless it's a null value or empty string unfortunately, postgres isn't smart enough to know that the when p_param below is null, that the WHERE condition can be ignored select * from table where name in (Coalesce(p_param, name)) which is the same as: select *

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
doh! tom, let me know if you decide to hack out a fix for this one of these nights ;) thanks for your help. On Feb 19, 2008 9:45 PM, Tom Lane <[EMAIL PROTECTED]> wrote: > "Postgres User" <[EMAIL PROTECTED]> writes: > > Yes that works, but the whole point of the exercise is replace many OR > > sta

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Tom Lane
"Postgres User" <[EMAIL PROTECTED]> writes: > Yes that works, but the whole point of the exercise is replace many OR > statements with 1 regex expression. So it's not what I'm looking for. Unfortunately, Postgres is not as intelligent as you are. There is no mechanism to rewrite a multi-branch r

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
im trying to allow the client to pass a varchar param into my function, and want to avoid any parsing of the parameter inside the function, or code to build a sql string. if the function can use this code, it will be compiled and optimized (unlike a dynamic sql stirng) select * from mytable where

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Chris
Postgres User wrote: Yes that works, but the whole point of the exercise is replace many OR statements with 1 regex expression. So it's not what I'm looking for. Why do you want it done this way? You can build an array of strings to check and use an in clause. Using php : $checks = array('A

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
Yes that works, but the whole point of the exercise is replace many OR statements with 1 regex expression. So it's not what I'm looking for. On Feb 19, 2008 9:16 PM, Chris <[EMAIL PROTECTED]> wrote: > Postgres User wrote: > > Thanks, my dumb mistake. > > I need to perform the equivalent of a WHER

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Chris
Postgres User wrote: Thanks, my dumb mistake. I need to perform the equivalent of a WHERE clause OR expression using regex to match exact strings. _ this example hits the index: select * from eod where name ~ '^BA$' but wh

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
Thanks, my dumb mistake. I need to perform the equivalent of a WHERE clause OR expression using regex to match exact strings. _ this example hits the index: select * from eod where name ~ '^BA$' but when I try to add another

Re: [GENERAL] Regex query not using index

2008-02-19 Thread Erik Jones
On Feb 19, 2008, at 9:32 PM, Postgres User wrote: I'm running a simple query on 8.2. With this syntax, Explain indicate that the index is scanned: select * from eod where name = 'AA' However, when I change the query to use simple regex: select * from eod where name ~ 'AA' now Explain indicate

[GENERAL] Regex query not using index

2008-02-19 Thread Postgres User
I'm running a simple query on 8.2. With this syntax, Explain indicate that the index is scanned: select * from eod where name = 'AA' However, when I change the query to use simple regex: select * from eod where name ~ 'AA' now Explain indicates a seq scan: Index Scan using equity_eod_symbol_idx