postgresql [42883] 错误 : function to_tsvector ("unknown", "unknown")不存在

标签 postgresql full-text-search

我是 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 工作的“hello world”,但我什至无法让它返回。我将 DataGrip 2020.2 与 Postgres 一起使用,但不确定如何查看我正在使用的 postgres 版本(我认为这是较新的版本)。我上面的代码有明显的错误吗?

最佳答案

您可以尝试检查使用了哪些类型(我正在使用psql client`):

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)

charactercharacter 类型没有任何变体。

您的第一个查询正在我的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)

当你想使用显式类型时,可以使用regconfigtext:

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)

关于postgresql [42883] 错误 : function to_tsvector ("unknown", "unknown")不存在,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66253465/

相关文章:

database - 记录两次插入数据库

python - 线程和 Django 数据库创建操作

MySQL 全文搜索列值?

postgresql - 未使用 Postgres GIN 索引,始终进行 SEQ 扫描

c - "cacheline aligned"是什么意思?

postgresql - Postgresql 中分组 LIMIT 10

java - AppEngine Java 全文。按日期排序适用于本地计算机,但未部署(SDK 1.6.6)

database - 在服务器中实现自动完成的最佳方式是什么?

java - 在 Java 中实现 Lucene 搜索的最佳实践

postgresql - 套接字 : operation not permitted when connecting to cloudsql