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

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.

主站蜘蛛池模板: 三门县| 济宁市| 安泽县| 舟曲县| 厦门市| 罗平县| 峨山| 阜新市| 台中市| 育儿| 织金县| 瓮安县| 大港区| 天祝| 兰州市| 凤凰县| 霍林郭勒市| 萨嘎县| 府谷县| 邵武市| 大理市| 仙游县| 兴业县| 乌海市| 乌拉特前旗| 安顺市| 锦州市| 桐梓县| 延长县| 和硕县| 英吉沙县| 龙岩市| 保德县| 长阳| 绥中县| 遵化市| 松江区| 靖安县| 江达县| 聂荣县| 顺昌县|