postgresql - postgresql [42883] 错误:函数 to_tsvector("unknown", "unknown") 不存在
问题描述
我是 postgresql 的新手,正在尝试使用全文搜索,to_tsvector
但是我遇到了错误。
SQL 和错误
SELECT to_tsvector('english', 'The quick brown fox jumped over the lazy dog.');
[42883] ERROR: function to_tsvector("unknown", "unknown") does not exist Hint: No function matches the given name and argument types. You may need to add explicit type casts.
不同尝试的 SQL 和错误
SELECT to_tsvector('english'::character, 'The quick brown fox jumped over the lazy dog.'::character);
[42883] ERROR: function to_tsvector(character, character) does not exist Hint: No function matches the given name and argument types. You may need to add explicit type casts.
这令人沮丧,因为这感觉就像让 to_tsvector 工作的“你好世界”,但是我什至无法让它返回。我将 DataGrip 2020.2 与 Postgres 一起使用,但不确定如何查看我使用的 postgres 版本(我认为它是较新版本)。我上面的代码有明显的错误吗?
解决方案
您可以尝试检查使用了哪些类型(我使用的是psql
客户端):
postgres=# \df to_tsvector
List of functions
┌────────────┬─────────────┬──────────────────┬─────────────────────┬──────┐
│ Schema │ Name │ Result data type │ Argument data types │ Type │
╞════════════╪═════════════╪══════════════════╪═════════════════════╪══════╡
│ pg_catalog │ to_tsvector │ tsvector │ json │ func │
│ pg_catalog │ to_tsvector │ tsvector │ jsonb │ func │
│ pg_catalog │ to_tsvector │ tsvector │ regconfig, json │ func │
│ pg_catalog │ to_tsvector │ tsvector │ regconfig, jsonb │ func │
│ pg_catalog │ to_tsvector │ tsvector │ regconfig, text │ func │
│ pg_catalog │ to_tsvector │ tsvector │ text │ func │
└────────────┴─────────────┴──────────────────┴─────────────────────┴──────┘
(6 rows)
character
type ,没有任何变体character
。
您的第一个查询正在我的 comp 中工作。请检查您使用的 Postgres 版本。较旧的(非常旧的 - 不支持的版本)Postgres 没有此功能
postgres=# SELECT to_tsvector('english', 'The quick brown fox jumped over the lazy dog.');
┌───────────────────────────────────────────────────────┐
│ to_tsvector │
╞═══════════════════════════════════════════════════════╡
│ 'brown':3 'dog':9 'fox':4 'jump':5 'lazi':8 'quick':2 │
└───────────────────────────────────────────────────────┘
(1 row)
当你想使用显式类型时,你可以使用regconfig
and text
:
postgres=# SELECT to_tsvector('english'::regconfig,
'The quick brown fox jumped over the lazy dog.'::text);
┌───────────────────────────────────────────────────────┐
│ to_tsvector │
╞═══════════════════════════════════════════════════════╡
│ 'brown':3 'dog':9 'fox':4 'jump':5 'lazi':8 'quick':2 │
└───────────────────────────────────────────────────────┘
(1 row)
推荐阅读
- python - 显示所有根节点、父节点和子节点(甚至是重复节点)的树图
- angular - 更改卡片颜色的指令
- javascript - 如果子组件中有相关数据,则仅在父组件中显示图标,但为了获得数据,我必须单击该图标
- nginx - 更新 Nginx 块来做两件不起作用的事情
- python - Bigquery api 使用 python Api
- laravel - 如何在 laravel 中过滤模型的关系?
- arrays - 在 Google 表格中,按名称而不是列号链接到列
- java - 在 JOOQ 中实现 batchMerge()
- python - 从 url 调用 django 应用程序中的函数
- python - Pandas:根据某个时间间隔将数据集拆分为多个周期