Re: Substring

Поиск
Список
Период
Сортировка
От Fernando Hevia
Тема Re: Substring
Дата
Msg-id 9CC5D98DF7ED4FE7AFC70F08F75021E3@iptel.com.ar
обсуждение исходный текст
Ответ на Re: Substring  (Raj Mathur <raju@linux-delhi.org>)
Список pgsql-sql

> >
> > Given that tablename is "voipdb"; I wonder if OP really 
> wants to write 
> > a query that finds the row where argument to function 
> matches the most 
> > number of leading characters in "prefix".
> >
> > If voipdb table contains:  ab, abc, def, defg; then calling 
> function 
> > with "abc" or "abcd" returns "abc" and calling function with "defh"
> > returns "def".
> >
> > If this is the real problem to be solved; then brute force is one 
> > solution; but I'm left wondering if a single query might return 
> > desired result (a single row).
> 
> Something like this may help in that case (note, we're 
> completely in the realm of creating imaginary problems and 
> solving them now :)
> 
> select * from voipdb where prefix <= string order by prefix 
> desc limit 1;
> 
> Regards,
> 
> -- Raju

Hum, I wonder if some kind of best-matching query is what you are looking
for:
   SELECT *   FROM voipdb   WHERE prefix IN (      SELECT substr(string, 1, i)      FROM generate_series(1,
length(string))i   );
 


Cheers,
Fernando.



В списке pgsql-sql по дате отправления:

Предыдущее
От: Raj Mathur
Дата:
Сообщение: Re: Substring
Следующее
От: venkat
Дата:
Сообщение: Postgresql PostGIS installation on Widows Server 2003