Re: Question about pattern matching - Mailing list pgsql-general

From Julius Tuskenis
Subject Re: Question about pattern matching
Date
Msg-id 495121BE.2050107@gmail.com
Whole thread Raw
In response to Question about pattern matching  (dimitris.sakellarios@telesuite.gr)
List 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.sakellarios@telesuite.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.
>
>

pgsql-general by date:

Previous
From: Craig Ringer
Date:
Subject: Re: Question about pattern matching
Next
From: "Grzegorz Jaśkiewicz"
Date:
Subject: Re: Question about pattern matching