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

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.

主站蜘蛛池模板: 吉首市| 铜鼓县| 安图县| 阜康市| 永济市| 友谊县| 海林市| 阜新市| 建始县| 工布江达县| 舟曲县| 兴海县| 永昌县| 张家港市| 龙门县| 改则县| 宁化县| 老河口市| 安丘市| 兴隆县| 航空| 兴安县| 大田县| 长寿区| 杨浦区| 依兰县| 西丰县| 沁水县| 大厂| 白山市| 儋州市| 西林县| 富源县| 泾川县| 丁青县| 镇远县| 苍溪县| 淮阳县| 龙江县| 定南县| 淮滨县|