↑↓ 选择 ↵ 打开 ⌫ 改范围 完整检索页

pgsql.cc 提供对 postgresql.org 官网内容的中文翻译,由 Pigsty 团队维护。

百科 / SQL 状态码 / Class 42 语法错误或访问规则违反

42P22 indeterminate_collation

无法确定排序规则

ERROR 源码确认 参考 未实测

条件名
indeterminate_collation
宏名称
ERRCODE_INDETERMINATE_COLLATION
最早已知存在
9.1.0
状态
有效

版本覆盖

版本条依据已采样构建显示;灰色版本可能尚未采样,悬停可查看。手册链接随版本选择,源码和运行证据保持原核验构建。

速览

42P22(indeterminate_collation)需要唯一排序规则的操作没有明确可用的排序规则。

含义

当选定操作需要可用的排序规则,但推导结果为空(通常表现为 InvalidOid)时,会报 42P22。这与 42P21 不同:这里的调用方消息指出无法继续的具体操作,而不是列出两个显式排序规则名称。固定核心调用方包括字符串哈希或比较、索引和分区表达式、CTAS 与视图输出列、正则表达式、LIKE/ILIKE 以及格式化函数。

诊断

先读取 primary 消息指出的操作,再追踪字符串表达式到应当选择排序规则的边界。哈希或比较消息指向运算符或值表达式;索引或分区消息指向定义表达式;CTAS 或视图列消息指向输出列;正则、LIKE 和 ILIKE 消息指向模式操作数;%s function 消息会指出格式化函数。固定调用方提供相同的 HINT:Use the COLLATE clause to set the collation explicitly.。应在表达式或声明列的语义边界做明确选择,并把这种缺少排序规则的要求与 42P21 中已知选择之间的冲突区分开。

处理

在真正拥有语义选择的表达式或输出列边界添加 COLLATE,必要时重建受影响的索引、分区、视图或 CTAS 定义。在该排序规则下核对比较、哈希、模式、正则和格式化行为;不要为了消除一个调用方错误而全局修改数据库 locale。如果该 ERROR 发生在显式事务中,重试前先 ROLLBACK,或回滚到错误前的保存点;自动提交模式下,连接返回空闲后即可提交修正语句。

消息

固定源码中的代表性消息包括:

  • ERROR message: could not determine which collation to use for string hashing; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: no collation was derived for column "%s" with collatable type %s; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for index expression; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for partition expression; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for view column "%s"; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for regular expression; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for %s function; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for LIKE; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for ILIKE; HINT: Use the COLLATE clause to set the collation explicitly.
  • ERROR message: could not determine which collation to use for string comparison; HINT: Use the COLLATE clause to set the collation explicitly.

占位符由实际对象、列或参数填充。

报文模板

源码里的格式串,不是某一次运行的输出。%s 之类是占位符,实际报文会填入对象名与取值。适用范围一栏是核验时留下的原始英文记录,未经翻译。

主消息 could not determine which collation to use for string hashing
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/access/hash/hashfunc.c(lines 278-281) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 no collation was derived for column "%s" with collatable type %s
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/commands/createas.c(lines 198-203) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for index expression
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/commands/indexcmds.c(lines 2105-2108) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for partition expression
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/commands/tablecmds.c(lines 20041-20044) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for view column "%s"
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/commands/view.c(lines 76-80) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for regular expression
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/regex/regc_pg_locale.c(lines 239-242) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for %s function
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/utils/adt/formatting.c(lines 1654-1658) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for LIKE
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/utils/adt/like.c(lines 160-163) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for ILIKE
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/utils/adt/like.c(lines 191-194) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

主消息 could not determine which collation to use for string comparison
HINT Use the COLLATE clause to set the collation explicitly.
主消息 · errhint Use the COLLATE clause to set the collation explicitly.

来源: 来源:src/backend/utils/adt/varchar.c(lines 735-738) @ REL_18_6

适用范围:Placeholders remain dynamic source fields; no concrete runtime value is claimed.

版本

锁定目录显示该条件最早见于 PostgreSQL 9.1.0;行为说明固定在 PostgreSQL 18.6 源码,目录存在范围不等于每条消息或功能都从该版本开始。

来源

证据

断言

每条断言都写明了是怎么核实的,以及它不覆盖什么。这一层是核验时留下的原始英文记录,照原样呈现,未经翻译。

同类 SQL 状态码

状态码 条件名 宏名称 严重等级 版本
Class 42 语法错误或访问规则违反 Syntax Error or Access Rule Violation 44 个 ↗
42000 syntax_error_or_access_rule_violation ERRCODE_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION ERROR 7.4 起已知
语法错误或访问规则违反的总类,见具体子码。 有效
42501 insufficient_privilege ERRCODE_INSUFFICIENT_PRIVILEGE ERROR 7.4 起已知
当前角色对目标对象的权限不足。 有效
42601 syntax_error ERRCODE_SYNTAX_ERROR ERROR 7.4 起已知
SQL 语句存在语法错误,解析器拒绝执行。 有效
42602 invalid_name ERRCODE_INVALID_NAME ERROR 7.4 起已知
名称不合法,如 enum 标签超出长度限制。 有效
42611 invalid_column_definition ERRCODE_INVALID_COLUMN_DEFINITION ERROR 7.4 起已知
列定义无效,如继承的父表默认值冲突。 有效
42622 name_too_long ERRCODE_NAME_TOO_LONG ERROR 7.4 起已知
标识符或 name 值超出长度上限。 有效
42701 duplicate_column ERRCODE_DUPLICATE_COLUMN ERROR 7.4 起已知
同一定义中重复指定了同名列。 有效
42702 ambiguous_column ERRCODE_AMBIGUOUS_COLUMN ERROR 7.4 起已知
列引用有歧义,多个表都有该列名。 有效
42703 undefined_column ERRCODE_UNDEFINED_COLUMN ERROR 7.4 起已知
引用的列在目标关系中不存在。 有效
42704 undefined_object ERRCODE_UNDEFINED_OBJECT ERROR 7.4 起已知
引用的数据库对象不存在,如触发器或类型。 有效
42710 duplicate_object ERRCODE_DUPLICATE_OBJECT ERROR 7.4 起已知
要定义的对象名已被占用,如重复 CREATE TYPE。 有效
42712 duplicate_alias ERRCODE_DUPLICATE_ALIAS ERROR 7.4 起已知
同一查询命名空间中重复使用了表别名。 有效
42723 duplicate_function ERRCODE_DUPLICATE_FUNCTION ERROR 7.4 起已知
同一模式下已存在同名同参数类型的函数。 有效
42725 ambiguous_function ERRCODE_AMBIGUOUS_FUNCTION ERROR 7.4 起已知
函数调用有多个候选,无法选出最佳匹配。 有效
42803 grouping_error ERRCODE_GROUPING_ERROR ERROR 7.4 起已知
分组查询输出了既未分组也未聚合的列。 有效
42804 datatype_mismatch ERRCODE_DATATYPE_MISMATCH ERROR 7.4 起已知
表达式类型与目标上下文要求的类型不符。 有效
42809 wrong_object_type ERRCODE_WRONG_OBJECT_TYPE ERROR 7.4 起已知
命令本身有效,但不能作用于该类对象。 有效
42830 invalid_foreign_key ERRCODE_INVALID_FOREIGN_KEY ERROR 7.4 起已知
外键在被引用列上找不到合格的唯一键。 有效
42846 cannot_coerce ERRCODE_CANNOT_COERCE ERROR 7.4 起已知
源类型到目标类型之间没有可用的 cast。 有效
42883 undefined_function ERRCODE_UNDEFINED_FUNCTION ERROR 7.4 起已知
按名称和参数类型找不到匹配的函数或操作符。 有效
428C9 generated_always ERRCODE_GENERATED_ALWAYS ERROR 10.0 起已知
向身份列或生成列赋值,这类列只接受 DEFAULT。 有效
42939 reserved_name ERRCODE_RESERVED_NAME ERROR 7.4 起已知
对象名使用了保留名称,如模式或表空间。 有效
42P01 undefined_table ERRCODE_UNDEFINED_TABLE ERROR 7.4 起已知
引用的表、视图或其他关系不存在。 有效
42P02 undefined_parameter ERRCODE_UNDEFINED_PARAMETER ERROR 7.4 起已知
查询引用了解析器未知的位置参数,如 $1。 有效
42P03 duplicate_cursor ERRCODE_DUPLICATE_CURSOR ERROR 7.4 起已知
游标或 portal 名称与已有的冲突。 有效
42P04 duplicate_database ERRCODE_DUPLICATE_DATABASE ERROR 7.4 起已知
集群中已存在同名数据库。 有效
42P05 duplicate_prepared_statement ERRCODE_DUPLICATE_PSTATEMENT ERROR 7.4 起已知
当前会话已有同名的服务端预备语句。 有效
42P06 duplicate_schema ERRCODE_DUPLICATE_SCHEMA ERROR 7.4 起已知
要创建的模式名在当前数据库中已存在。 有效
42P07 duplicate_table ERRCODE_DUPLICATE_TABLE ERROR 7.4 起已知
关系名已存在,或继承父项重复。 有效
42P08 ambiguous_parameter ERRCODE_AMBIGUOUS_PARAMETER ERROR 7.4 起已知
参数存在但无法推导出一致而具体的类型。 有效
42P09 ambiguous_alias ERRCODE_AMBIGUOUS_ALIAS ERROR 7.4 起已知
一个表引用对应多个关系命名空间项。 有效
42P10 invalid_column_reference ERRCODE_INVALID_COLUMN_REFERENCE ERROR 7.4 起已知
列引用不符合该操作的契约,如 COPY 生成列。 有效
42P11 invalid_cursor_definition ERRCODE_INVALID_CURSOR_DEFINITION ERROR 7.4 起已知
游标声明违反定义阶段规则,如 SCROLL 选项冲突。 有效
42P12 invalid_database_definition ERRCODE_INVALID_DATABASE_DEFINITION ERROR 7.4 起已知
数据库定义无效,核心源码中未见触发路径。 有效
42P13 invalid_function_definition ERRCODE_INVALID_FUNCTION_DEFINITION ERROR 7.4 起已知
函数、聚合或触发器声明在校验阶段失败。 有效
42P14 invalid_prepared_statement_definition ERRCODE_INVALID_PSTATEMENT_DEFINITION ERROR 7.4 起已知
PREPARE 定义预备语句时失败。 有效
42P15 invalid_schema_definition ERRCODE_INVALID_SCHEMA_DEFINITION ERROR 7.4 起已知
CREATE SCHEMA 的模式声明不一致被拒绝。 有效
42P16 invalid_table_definition ERRCODE_INVALID_TABLE_DEFINITION ERROR 7.4 起已知
表定义无效,如分区键或主键规则冲突。 有效
42P17 invalid_object_definition ERRCODE_INVALID_OBJECT_DEFINITION ERROR 7.4 起已知
对象定义无效,如继承、生成列或规则冲突。 有效
42P18 indeterminate_datatype ERRCODE_INDETERMINATE_DATATYPE ERROR 7.4 起已知
无法推断表达式或参数的数据类型。 有效
42P19 invalid_recursion ERRCODE_INVALID_RECURSION ERROR 8.4.0 起已知
递归查询结构不合法,执行前被检查拒绝。 有效
42P20 windowing_error ERRCODE_WINDOWING_ERROR ERROR 8.4.0 起已知
窗口函数调用或框架边界定义不合法。 有效
42P21 collation_mismatch ERRCODE_COLLATION_MISMATCH ERROR 9.1.0 起已知
参与运算的排序规则不兼容,产生冲突。 有效
42P22 indeterminate_collation ERRCODE_INDETERMINATE_COLLATION ERROR 9.1.0 起已知
操作需要唯一排序规则,但无法确定。 有效