Re: Regex query not using index

From: "Postgres User" <postgres(dot)developer(at)gmail(dot)com>
To: Chris <dmagick(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Regex query not using index
Date: 2008-02-20 05:58:36
Message-ID: b88c3460802192158g664290e5ka31be94eb48aea69@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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 * from table where name in (name)

postgres does a row scan on the above sql. too slow.

On Feb 19, 2008 9:34 PM, Chris <dmagick(at)gmail(dot)com> wrote:
> 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('AA', 'BA');
>
> $query = "select * from table where name in ('" . implode("','",
> $checks) . "')";
>
> and it should use an index (up to a point anyway).
>
> --
>
> Postgresql & php tutorials
> http://www.designmagick.com/
>

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Chris 2008-02-20 06:05:49 Re: Regex query not using index
Previous Message Postgres User 2008-02-20 05:52:17 Re: Regex query not using index