- Mastering PostgreSQL 9.6
- Hans Jurgen Schonig
- 199字
- 2021-07-09 19:57:09
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.
推薦閱讀
- PowerShell 3.0 Advanced Administration Handbook
- Visual C# 2008開發技術實例詳解
- 大數據處理平臺
- Splunk Operational Intelligence Cookbook
- 基于單片機的嵌入式工程開發詳解
- 基于神經網絡的監督和半監督學習方法與遙感圖像智能解譯
- Hands-On SAS for Data Analysis
- Xilinx FPGA高級設計及應用
- Unreal Development Kit Game Design Cookbook
- Hands-On Deep Learning with Go
- EJB JPA數據庫持久層開發實踐詳解
- PostgreSQL 10 High Performance
- 網頁設計與制作
- Practical Network Automation
- Arduino創意機器人入門:基于Mind+