Re: Does string a begin with string b?

From: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
To: Robert James <srobertjames(at)gmail(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: Does string a begin with string b?
Date: 2013-08-16 18:21:24
Message-ID: CAMkU=1xjq=fvtUyeQ447A=CJ2+B8EVDY-O8LitfqxE1YO4gDTQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, Aug 16, 2013 at 11:04 AM, Robert James <srobertjames(at)gmail(dot)com> wrote:
> What's the best way to check if string a begins with string b?
>
> Both a and b are coming from fields in a table.
>
> Requirements:
>
> * Either a or b might have special chars (such as '%') in them which
> should NOT do anything special - they're just plain strings, not
> regular expressions.
> * a and b can be of arbitrary length (no fixed limits)

where substring(a,1,length(b)) = b

> * Ideally, I'd like it to be transparent to the query engine, so that
> it can use indexes. If both a and b are indexed, it's possible in
> theory to use the index to do most of the work - but I can't come up
> with a query that makes use of it.

I wouldn't count on this being much help. It might be able to use an
index-only-scan if both a and b are in the index, but then you would
just be treating the index as a skinny table, not as an index.

Cheers,

Jeff

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Grittner 2013-08-16 21:46:55 Re: Using an index to materialize a function
Previous Message John R Pierce 2013-08-16 18:11:55 Re: need help