where 子句中的 lower() 与模式不匹配

lower() in where clause does not match pattern

select version();
                                                   version
--------------------------------------------------------------------------------------------------------------
 PostgreSQL 9.3.14 on x86_64-redhat-linux-gnu, compiled by gcc (GCC) 4.8.3 20140911 (Red Hat 4.8.3-9), 64-bit
(1 row)

查询:

select foreign_text
, lower(t.foreign_text) = 'спорт' c1
, convert_to(lower(t.foreign_text),'utf8') = convert_to(lower('спорт'),'utf8') c2
from translation_keywords_from_ru_to_en t
where
  lower(t.foreign_text) = 'спорт'
;
 foreign_text | c1 | c2
--------------+----+----
(0 rows)

正在删除 where 中的 lower,留在列列表中:

select foreign_text
, lower(t.foreign_text) = 'спорт' c1
, convert_to(lower(t.foreign_text),'utf8') = convert_to(lower('спорт'),'utf8') c2
from translation_keywords_from_ru_to_en t
where
  t.foreign_text = 'спорт'
;
 foreign_text | c1 | c2
--------------+----+----
 спорт        | t  | t
 спорт        | t  | t
(2 rows)

请注意 c1 (lower(t.foreign_text) = 'спорт') 是 true,而在 WHERE 之前的 select 中显然不是条款。

也对:

where lower(t.foreign_text collate "fr_FR") = 'спорт'
where initcap(t.foreign_text) = initcap('спорт')
where convert_to(lower(t.foreign_text),'utf8') = convert_to(lower('спорт'),'utf8')
where upper(t.foreign_text) = upper('спорт')

但错误:

where lower(t.foreign_text) = 'спорт'
where lower(t.foreign_text) = lower('спорт')

not find anything specific lower()。如果我将 lower(t.foreign_text) 转换为 "utf bytea",现象就会消失。

我的情况:一旦查询insert into ... where not exists (... where lower(t.foreign_text) = lower('спорт')) 找不到行,它就会尝试插入重复项。我看到了如何重写查询以避免它。然而我很困惑。

问题:我是否遗漏了一些东西并且 lower(t.foreign_text) = 'спорт'where 中可能是错误的,但在列列表中 true 或者我打了一些某种错误?

foreign_text 属于 text 类型

\l+ db
                                               List of databases
  Name  | Owner | Encoding |   Collate   |    Ctype    | Access privileges |  Size  | Tablespace | Description
--------+-------+----------+-------------+-------------+-------------------+--------+------------+-------------
      db|     un| UTF8     | en_US.UTF-8 | en_US.UTF-8 |                   | 406 GB | pg_default 

|

我能想到的唯一解释是您有一个索引 ON translation_keywords_from_ru_to_en (lower(foreign_text)),但该索引已损坏。

如果在查询之前运行以下内容,是否会得到相同的结果:

SET enable_indexscan = off;
SET enable_indexonlyscan = off;
SET enable_bitmapscan = off;

这将避免在查询中使用索引。