Re: Longest prefix matching CTE

From: Steve Atkins <steve(at)blighty(dot)com>
To: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Longest prefix matching CTE
Date: 2015-02-24 23:57:47
Message-ID: 1374F64F-3722-4A97-A76C-FFAA3DDF94F0@blighty.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On Feb 24, 2015, at 3:50 PM, Tim Smith <randomdev4+postgres(at)gmail(dot)com> wrote:

>
>
> The goal being to match the longest prefix given a full phone number, e.g.
>
>
> 61234567890 would match "australia proper 61"
> whilst
> 61134567890 would match "Australia premium 6113"
> and
> 61894321010 would match "Australia - Sydney 61893"
>
> I know the answer involves Postgres CTE, but I haven't used CTEs much
> yet... let alone in complex queries such as this.
>
> Thanking you all in advance for your kind help.

There's probably a CTE approach for it, but you might want to look
at https://github.com/dimitri/prefix too - it's an extension that's designed
specifically for longest prefix matching, and that uses gist indexes to
do it efficiently.

Cheers,
Steve

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Frost 2015-02-25 01:37:31 Re: Row-level Security vs Application-level authz
Previous Message Tim Smith 2015-02-24 23:50:33 Longest prefix matching CTE