↑↓ 选择↵ 打开⌫ 切换范围完整搜索

PG.CENTER 连接 PostgreSQL 文档、百科与生态知识。由 Pigsty 维护。

Wiki / SQLSTATE

22025 — invalid_escape_sequence

转义序列无效,如 ESCAPE 参数非单字符。

英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。

当前阅读 PG 18·选择有来源记录的版本

aliases
未知
class name
Data Exception
condition name
invalid_escape_sequence
lang
en
sqlstate
22025

版本定义 PG 18

22025

速览 {#at-a-glance}

转义序列对具体消费方无效。固定路径区分 LIKE 的 ESCAPE 参数既非空也非单字符、LIKE pattern 以转义字符结束、正则翻译器的转义参数长度规则,以及格式错误的 \u/\U Unicode 转义。

代表性报文 {#messages}

代表性消费方使用以下首要文本和提示:

| 消费方/守卫 | 首要文本和提示 | | --- | --- | | LIKE 或 SQL 正则翻译的转义长度 | invalid escape string;HINT:Escape string must be empty or one character. | | LIKE pattern 以转义符结尾 | LIKE pattern must not end with escape character | | 扫描器发现格式错误的 Unicode 转义 | invalid Unicode escape;HINT:Unicode escapes must be \uXXXX or \UXXXXXXXX. |

含义 {#meaning}

22025 由消费方自己的转义守卫发出。LIKE 要求 ESCAPE 字符串为空或一个字符,并拒绝以转义字符结尾的 pattern;SQL 正则翻译辅助函数对其转义参数也使用空字符串或单字符规则;核心扫描器对格式错误的 Unicode 转义给出 \uXXXX/\UXXXXXXXX 提示。这些情况不同于 22019 的转义字符语义和 2200C 的 SIMILAR 分隔符溢出;regexp_replace 的 option 或 start/occurrence 参数错误则是 22023 参数校验路径。

诊断 {#diagnosis}

先确认消费方再修改反斜杠:LIKE ESCAPE 参数、LIKE pattern、SQL 正则翻译,还是扩展字符串字面量的 Unicode 扫描。检查转义值是否为空字符串或单字符、LIKE pattern 是否以转义符结尾,以及 Unicode 转义是否具备所需 \u/\U 长度。不要把所有正则替换或 SIMILAR 语法错误都叫作 22025,应以实际 SQLSTATE 和首要报文分类。

处理 {#response}

按消费方要求提供转义字符串和 pattern,并保留有意使用的空字符串,不要将其理解为 SQL NULL。Unicode 语法错误应按扫描器要求使用 \uXXXX 或 \UXXXXXXXX。如果 ERROR 发生在显式事务中,应先 ROLLBACK 或回滚到既有保存点再重试;自动提交可重试修正后的语句。

版本 {#versions}

锁定目录从 7.4 起记录该条件;本页固定源码路径为 PostgreSQL 18.6。未声称本页有自然运行观察。

相关 {#related}

22019、2200C、22023

来源 {#sources}

LIKE 守卫在 src/backend/utils/adt/like_match.c#L159-165 和 #L439-449;SQL 正则翻译的转义长度守卫见 src/backend/utils/adt/regexp.c#L793-805;格式错误的 Unicode 转义在 src/backend/parser/scan.l#L697-704。结构化证据记录保留确切首要报文、提示和消费方边界;本页未运行自然案例。

比较版本

SQLSTATE 证据与已记录的运行版本

claims · identity
{
  "claim_id": "identity",
  "limits": "",
  "method": "Read the fixed errcodes row and macro.",
  "position": 0,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "22025 is invalid_escape_sequence in SQLSTATE Class 22"
}
claims · resolved-path
{
  "claim_id": "resolved-path",
  "limits": "Source confirmation is not a natural runtime observation.",
  "method": "Read complete source contexts for the representative guards.",
  "position": 1,
  "runtime": [],
  "sources": [
    "src.like.pattern",
    "src.like.escape",
    "src.regexp.escape",
    "src.scan.unicode"
  ],
  "statement": "Fixed PostgreSQL 18.6 LIKE, SQL regular-expression translation, and core scanner paths bind distinct escape-length, trailing-pattern, and malformed-Unicode guards."
}
claims · history
{
  "claim_id": "history",
  "limits": "",
  "method": "Use catalogue presence and history boundaries.",
  "position": 2,
  "runtime": [],
  "sources": [
    "src.errcodes.18.6"
  ],
  "statement": "The locked catalogue records 22025 from 7.4 without proving an exact implementation introduction date."
}
claims · neighboring-codes
{
  "claim_id": "neighboring-codes",
  "limits": "",
  "method": "Read the adjacent consumers and their explicit errcodes.",
  "position": 3,
  "runtime": [],
  "sources": [
    "src.regexp.escape",
    "src.like.escape"
  ],
  "statement": "SIMILAR separator overflow and regexp_replace parameter validation use different SQLSTATE paths (2200C/22023) and are not folded into 22025."
}
messages · message.invalid-escape-like
{
  "limits": "",
  "message_id": "message.invalid-escape-like",
  "path": "",
  "position": 0,
  "raw": {
    "hint_template": "Escape string must be empty or one character.",
    "id": "message.invalid-escape-like",
    "primary_template": "invalid escape string",
    "severity_source": "ERROR",
    "sources": [
      "src.like.escape"
    ],
    "sqlstate": "22025"
  },
  "severity": "ERROR",
  "sources": [
    "src.like.escape"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "invalid escape string",
      "position": 0,
      "role": "",
      "template": "invalid escape string"
    },
    {
      "kind": "hint",
      "literal": "Escape string must be empty or one character.",
      "position": 1,
      "role": "",
      "template": "Escape string must be empty or one character."
    }
  ]
}
messages · message.like-trailing
{
  "limits": "",
  "message_id": "message.like-trailing",
  "path": "",
  "position": 1,
  "raw": {
    "id": "message.like-trailing",
    "primary_template": "LIKE pattern must not end with escape character",
    "severity_source": "ERROR",
    "sources": [
      "src.like.pattern"
    ],
    "sqlstate": "22025"
  },
  "severity": "ERROR",
  "sources": [
    "src.like.pattern"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "LIKE pattern must not end with escape character",
      "position": 0,
      "role": "",
      "template": "LIKE pattern must not end with escape character"
    }
  ]
}
messages · message.invalid-escape-regexp
{
  "limits": "",
  "message_id": "message.invalid-escape-regexp",
  "path": "",
  "position": 2,
  "raw": {
    "hint_template": "Escape string must be empty or one character.",
    "id": "message.invalid-escape-regexp",
    "primary_template": "invalid escape string",
    "severity_source": "ERROR",
    "sources": [
      "src.regexp.escape"
    ],
    "sqlstate": "22025"
  },
  "severity": "ERROR",
  "sources": [
    "src.regexp.escape"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "invalid escape string",
      "position": 0,
      "role": "",
      "template": "invalid escape string"
    },
    {
      "kind": "hint",
      "literal": "Escape string must be empty or one character.",
      "position": 1,
      "role": "",
      "template": "Escape string must be empty or one character."
    }
  ]
}
messages · message.invalid-unicode
{
  "limits": "",
  "message_id": "message.invalid-unicode",
  "path": "",
  "position": 3,
  "raw": {
    "hint_template": "Unicode escapes must be \\uXXXX or \\UXXXXXXXX.",
    "id": "message.invalid-unicode",
    "primary_template": "invalid Unicode escape",
    "severity_source": "ERROR",
    "sources": [
      "src.scan.unicode"
    ],
    "sqlstate": "22025"
  },
  "severity": "ERROR",
  "sources": [
    "src.scan.unicode"
  ],
  "templates": [
    {
      "kind": "primary",
      "literal": "invalid Unicode escape",
      "position": 0,
      "role": "",
      "template": "invalid Unicode escape"
    },
    {
      "kind": "hint",
      "literal": "Unicode escapes must be \\uXXXX or \\UXXXXXXXX.",
      "position": 1,
      "role": "",
      "template": "Unicode escapes must be \\uXXXX or \\UXXXXXXXX."
    }
  ]
}
sources · src.errcodes.18.6
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/errcodes.txt",
  "position": 0,
  "sha256": "6e8de346643ba84aa3c9c6a73360acfc7b2dfb89162c06c08ce9bf5bcd5bbcba",
  "source_id": "src.errcodes.18.6",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/errcodes.txt#L182"
}
sources · src.like.pattern
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/like_match.c",
  "position": 1,
  "sha256": "7cc02d42bc11e87e13cc61ea32f066627f9f5632dac37774160ae809b606b789",
  "source_id": "src.like.pattern",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/like_match.c#L159"
}
sources · src.like.escape
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/like_match.c",
  "position": 2,
  "sha256": "7cc02d42bc11e87e13cc61ea32f066627f9f5632dac37774160ae809b606b789",
  "source_id": "src.like.escape",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/like_match.c#L439"
}
sources · src.regexp.escape
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/utils/adt/regexp.c",
  "position": 3,
  "sha256": "8c54fe9e937ce03111b39da7bca89b22d6cb2de6b9ce5f7caf90c76bc7218e0e",
  "source_id": "src.regexp.escape",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/utils/adt/regexp.c#L793"
}
sources · src.scan.unicode
{
  "commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
  "docs_url": "",
  "kind": "upstream_source",
  "location": "",
  "path": "src/backend/parser/scan.l",
  "position": 4,
  "sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
  "source_id": "src.scan.unicode",
  "tag": "REL_18_6",
  "url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L697"
}

来源引用

完整定义与证据 JSON

定义来源

center · PostgreSQL 18 · english-manuals:533233a45112ea029b9088666c41ae8f6bdfbdfbcd94143492a681068c647492

正文语言: zh-Hans · english-manuals:533233a45112ea029b9088666c41ae8f6bdfbdfbcd94143492a681068c647492