Re: Finding rows with text columns beginning with other text columns

Поиск
Список
Период
Сортировка
От Christoph Zwerschke
Тема Re: Finding rows with text columns beginning with other text columns
Дата
Msg-id 4BE85D76.2040900@online.de
обсуждение исходный текст
Ответ на Re: Finding rows with text columns beginning with other text columns  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Ответы Re: Finding rows with text columns beginning with other text columns  (Alban Hertroys <dalroi@solfertje.student.utwente.nl>)
Список pgsql-general
Am 10.05.2010 11:50 schrieb Alban Hertroys:
 > On 10 May 2010, at 24:01, Christoph Zwerschke wrote:
 >
 >> select * from b join a on b.txt like a.txt||'%'
 >>
 >> I feel there should be a performat way to query these entries,
 >> but I can't come up with anything. Can anybody help me?
 >
 > Have you tried using substring instead of like?

How exactly? I tried this:

     substr(b.txt, 1, length(a.txt)) = a.txt

but it cannot be optimized and results in a nested loop, too.

It only works with a fixed length:

     substr(b.txt, 1, 3) = a.txt

So theoretically I could do something like

select * from b join a
on substr(b.txt, 1, 1) = a.txt and length(b.txt) = 1
union select * from b join a
on substr(b.txt, 1, 2) = a.txt and length(b.txt) = 2
union select * from b join a
on substr(b.txt, 1, 3) = a.txt and length(b.txt) = 3
union ...

... up to the maximum possible string length in a.txt. Not very elegant.

If the question is not finding text cols in b starting with text cols in
a, but text cols in b starting with text cols in a as their first word,
then the following join condition works very well:

     split_part(b.txt, ' ', 1) = a.txt

But I'm still looking for a simple solution to the original problem.

-- Christoph

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

Предыдущее
От: Daniel Scott
Дата:
Сообщение: Re: PostgreSQL 9.0 - support for RANGE value PRECEDING window functions
Следующее
От: Kynn Jones
Дата:
Сообщение: Re: How to do pg_dump + pg_restore within Perl script?