Skip site navigation (1) Skip section navigation (2)

Re: Question about pattern matching

From: "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com>
To: dimitris(dot)sakellarios(at)telesuite(dot)gr
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Question about pattern matching
Date: 2008-12-23 17:12:59
Message-ID: dcc563d10812230912r1638cd95jc827d1a57b034fd9@mail.gmail.com (view raw or flat)
Thread:
Lists: pgsql-general
On Tue, Dec 23, 2008 at 9:05 AM,  <dimitris(dot)sakellarios(at)telesuite(dot)gr> wrote:
> 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.

Without getting out the pgsql manual to write the code, I'd basically
append enough 0s to each candidate to pad them out to the same length,
all ending in one or more 0s, except the longest, which wouldn't need
padding.  Then I'd see which one matched.

In response to

Responses

pgsql-general by date

Next:From: Scott MarloweDate: 2008-12-23 17:13:29
Subject: Re: Question about pattern matching
Previous:From: Adrian KlaverDate: 2008-12-23 16:26:58
Subject: Re: Copy/delete issue

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group