Re: Longest prefix matching CTE - Mailing list pgsql-general

From Steve Atkins
Subject Re: Longest prefix matching CTE
Date
Msg-id 1374F64F-3722-4A97-A76C-FFAA3DDF94F0@blighty.com
Whole thread Raw
In response to Longest prefix matching CTE  (Tim Smith <randomdev4+postgres@gmail.com>)
Responses Re: Longest prefix matching CTE
List pgsql-general
On Feb 24, 2015, at 3:50 PM, Tim Smith <randomdev4+postgres@gmail.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



pgsql-general by date:

Previous
From: Tim Smith
Date:
Subject: Longest prefix matching CTE
Next
From: Stephen Frost
Date:
Subject: Re: Row-level Security vs Application-level authz