Textmatchning

Started by A Bover 17 years ago4 messagesgeneral
Jump to latest
#1A B
gentosaker@gmail.com

Hi.
I would like to compare two columns a and b and find all cases where
a is a part of b, like this
select * from mytable where a ilike b;

but that will not give me a row in the case when a = 'foo' and b='FOOTBALL'
and I want that to be a match.

So how do I rewrite my expression? I can't find any way to add % to
make it match the way I want.

#2Scott Marlowe
scott.marlowe@gmail.com
In reply to: A B (#1)
Re: Textmatchning

On Wed, Sep 17, 2008 at 12:36 PM, A B <gentosaker@gmail.com> wrote:

Hi.
I would like to compare two columns a and b and find all cases where
a is a part of b, like this
select * from mytable where a ilike b;

but that will not give me a row in the case when a = 'foo' and b='FOOTBALL'
and I want that to be a match.

So how do I rewrite my expression? I can't find any way to add % to
make it match the way I want.

where b ilike '%'||a||'%';

?

#3Edoardo Panfili
edoardo@aspix.it
In reply to: A B (#1)
Re: Textmatchning

A B ha scritto:

Hi.
I would like to compare two columns a and b and find all cases where
a is a part of b, like this
select * from mytable where a ilike b;

but that will not give me a row in the case when a = 'foo' and b='FOOTBALL'
and I want that to be a match.

So how do I rewrite my expression? I can't find any way to add % to
make it match the way I want.

It seems that the order is important.
http://www.postgresql.org/docs/8.3/interactive/functions-matching.html#FUNCTIONS-LIKE

select 'foo%' ilike 'FOOTBALL';
----------
f

but

select 'FOOTBALL' ilike 'foo%';
----------
t

Edoardo

#4Daniel Verite
daniel@manitou-mail.org
In reply to: A B (#1)
Re: Textmatchning

A B wrote:

I would like to compare two columns a and b and find all cases where
a is a part of b, like this
select * from mytable where a ilike b;

"a is a part of b" can simply be expressed as:
position(a in b)>0
and if you need case insensitivity:
position(upper(a) in upper(b))>0

Best regards,
--
Daniel
PostgreSQL-powered mail user agent and storage:
http://www.manitou-mail.org