array_to_tsvector() 是一个系统函数,用于将词元(lexeme)的 数组 转换为 tsvector。
array_to_tsvector() 在 PostgreSQL 9.6 中添加。
用法
array_to_tsvector (text[] ) →tsvector
提供的字符串在转换前不会被处理。
变更历史
- PostgreSQL 15
- 禁止创建空词元(提交 cbe25dcf)
- PostgreSQL 9.6
- 已添加(提交 6943a946)
示例
array_to_tsvector() 的基本用法示例
postgres=# SELECT array_to_tsvector(ARRAY['foo','bar','baz']); array_to_tsvector ------------------- 'bar' 'baz' 'foo' (1 row)
重复的值将被合并
postgres=# SELECT array_to_tsvector('{foo,bar,bar}'::text[]);
array_to_tsvector
-------------------
'bar' 'foo'
(1 row)
请注意,在 PostgreSQL 14 及更早版本中,可以创建空词元,例如:
postgres=# SELECT array_to_tsvector(ARRAY['','foo']); array_to_tsvector ------------------- '' 'foo' (1 row)
从 PostgreSQL 15 开始,此行为已被禁止。
postgres=# SELECT array_to_tsvector(ARRAY['','foo']); ERROR: lexeme array may not contain empty strings
参考资料
- PostgreSQL 文档: 文本搜索函数
