官术网_书友最值得收藏!

Digging into new SQL and developer-related functions

One of the most promising new features of PostgreSQL is the ability to perform phrase searching. Up to 9.5 it was only possible to search for words—phrase searching was very hard to do. 9.6 nicely removes this limitation. Here is an example of how it works:

test=# SELECT phraseto_tsquery('Under pressure') @@                   to_tsvector('Something was under some sort of pressure');

?column?

----------

f

(1 row)

test=# SELECT phraseto_tsquery('Under pressure') @@ to_tsvector('Under pressure by David Bowie hit number 1 again');

?column?

----------

t

(1 row)

The first query returns false because the words we are looking for do not occur in the desired order. In the second example, true is returned because there really is a proper match.

However, there is more: in 9.6 it is possible to check whether words show up in a certain order. In the following example, we want a word to be between united and nations:

test=# SELECT tsquery('united <2> nations') @@                     to_tsvector('are we really united, happy nations?');

?column?

----------

t

(1 row)

test=# SELECT tsquery('united <2> nations') @@ to_tsvector('are we really at united nations?');

?column?

----------

f

(1 row)

The second example returns false as there is no word between united and nations.

主站蜘蛛池模板: 泾源县| 莱州市| 永胜县| 白朗县| 康保县| 温州市| 宝丰县| 登封市| 邹城市| 黄梅县| 乐陵市| 东海县| 延边| 嫩江县| 通河县| 尼木县| 扶余县| 江孜县| 中山市| 四子王旗| 隆德县| 五大连池市| 桦南县| 同仁县| 肥城市| 中方县| 威宁| 彰化县| 大丰市| 鸡西市| 宜章县| 临桂县| 綦江县| 霸州市| 长乐市| 瓮安县| 保定市| 周口市| 江北区| 曲麻莱县| 隆化县|