From: | "Postgres User" <postgres(dot)developer(at)gmail(dot)com> |
---|---|
To: | "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
Cc: | "Tino Wildenhain" <tino(at)wildenhain(dot)de>, pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Regex query not using index |
Date: | 2008-02-20 16:51:55 |
Message-ID: | b88c3460802200851k202ebdd2x69ef078c3b0a8139@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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 will ignore when processing the query?
This syntax results in a seq scan: WHERE fielda = Coalesce(param, fielda)
because it applies only to non-nulls
Is there another way to write this- perhaps using your array syntax on
an empty array? Basically I'd PG to ignore the condition just as it
ignores WHERE 1 = 1
On Wed, Feb 20, 2008 at 8:31 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
> "Postgres User" <postgres(dot)developer(at)gmail(dot)com> 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 regex? If you aren't actually
> trying to expose regex capabilities to the users, you'll just be having
> to suppress a bunch of strange behaviors for special characters.
>
> ISTM that the best solution is to use an array-of-text parameter,
> along the lines of
>
> where name = any (array['Smith', 'Jones', ...])
>
> For what you're doing, you'd not actually want the array[] syntax,
> it would look more like
>
> where name = any ('{Smith,Jones}'::text[])
>
> This should optimize into an indexscan in 8.2 or later.
>
> regards, tom lane
>
From | Date | Subject | |
---|---|---|---|
Next Message | intelforum | 2008-02-20 17:25:41 | Re: Using sequences in SQL text files |
Previous Message | Carlo Stonebanks | 2008-02-20 16:32:53 | select...into non-temp table raises 'duplicate key ... pg_type_typname_nsp_index' |