当前位置: 动力学知识库 > 问答 > 编程问答 >

postgresql - How to select a word in a text SQL query?

问题描述:

On our PostgreSQL Database we have a field called Description. As you can guess this Description contains a lot of text and we would like to look inside this descriptions to find a certain word.

We tried contains and Charindex function but both are not working...

Any Idea how we can solve this?

Thank you very much!

Luca

网友答案:

You can use regular expressions with word delimiter markers:

select * from table
where description ~ ('\m' || 'yourword' || '\M');

Use ~* instead of ~ for case insensitive searches.

Note that using description LIKE '%yourword%' as @JNevill suggests will find that your word within other words as well, e.g. 'Jean-Luc Picard' LIKE '%car%' is true.

分享给朋友:
您可能感兴趣的文章:
随机阅读: