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

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.

主站蜘蛛池模板: 平塘县| 胶州市| 苏尼特左旗| 南安市| 盘锦市| 遂昌县| 泰来县| 鸡西市| 建水县| 津南区| 尼勒克县| 兴义市| 麻阳| 阳高县| 吉首市| 古丈县| 绥滨县| 赣榆县| 临海市| 兴城市| 德昌县| 宜黄县| 商水县| 防城港市| 垣曲县| 荔浦县| 黄石市| 麻栗坡县| 漠河县| 祁阳县| 巫山县| 高州市| 金华市| 阿坝县| 隆尧县| 哈密市| 阜康市| 茶陵县| 桦南县| 西贡区| 光山县|