Thursday, February 26. 2009A "Longest-Prefix" Solution for SQLTrackbacks
Trackback specific URI for this entry
No Trackbacks
Comments
Display comments as
(Linear | Threaded)
The more I think about it, the more I prefer the second option anyway – it’s more clear that it’s driving at the intended problem, that of "finding the longest prefix which matches" – use the where clause on locate() to say "where it matches", and the order by+locate to find the "longest". Here’s a similar expression that seems to work with SQL Server SELECT id, prefix from routes where charindex(prefix, ‘18005558355’) = 1 order by len(prefix) desc This should be the equivalent PgSQL: select id, number from prefixes where position(number in ‘18885558355’) = 1 order by length(number) desc limit 1; |
Calendar
QuicksearchCategoriesBlog AdministrationTemplate dropdownStatisticsLast entry: 2011-09-01 12:27
101 entries written
51 comments have been made
StatisticsLast entry: 2011-09-01 12:27
101 entries written
51 comments have been made
StatisticsLast entry: 2011-09-01 12:27
101 entries written
51 comments have been made
|
|||||||||||||||||||||||||||||||||||||||||||||||||