Re: Question about pattern matching

From: Julius Tuskenis <julius(dot)tuskenis(at)gmail(dot)com>
To:
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question about pattern matching
Date: 2008-12-23 17:37:02
Message-ID: 495121BE.2050107@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi, Dimitris

I think simple
SELECT TABLENAME.id
FROM TABLENAME
WHERE prm_patern ilike TABLENAME.candidate_pattern||'%'
ORDER BY |char_length(|TABLENAME.candidate_pattern) desc
LIMIT 1
should do the trick. (Provided TABLENAME is not very large of course)

Julius Tuskenis

dimitris(dot)sakellarios(at)telesuite(dot)gr rašė:
> TABLENAME
>
> id Candidate pattern
> -------------------------
> 1 0089258068520
> 2 008925806852
> 3 00892580685
> 4 0089258068
> 5 008925806
> 6 00892580
> 7 0089258
> 8 008925
> 9 00892
> 10 0089
> 11 008
> 12 00
> 13 0
>
>
> PATTERN
> -------
> 0089257000000
>
> QUESTION
> --------
> Pls let me know which is the best way to match the
> following pattern against this table and Receive id = 8
> that is the longest matching pattern from left to right.
>
> BR,
> Sakellarios Dimitris.
>
>

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Grzegorz Jaśkiewicz 2008-12-23 18:06:34 Re: Question about pattern matching
Previous Message Craig Ringer 2008-12-23 17:16:02 Re: Question about pattern matching