22P06 — nonstandard_use_of_escape_character
字符串字面量中反斜杠转义用法非标准。
英文手册覆盖始于 PostgreSQL 8.1. 来源历史与运行验证各自保留独立版本边界。
当前阅读 PG 18·选择有来源记录的版本
- aliases
- 未知
- class name
- Data Exception
- condition name
- nonstandard_use_of_escape_character
- lang
- en
- sqlstate
- 22P06
版本定义 PG 18
22P06
速览 {#at-a-glance}
SQL 扫描器发现反斜杠转义形式在当前字符串字面量规则下非标准或不安全。PostgreSQL 18.6 有一个不安全引号转义的 ERROR 分支,以及反斜杠-引号、反斜杠-反斜杠和其他转义用法的三个 WARNING 分支。
含义 {#meaning}
扫描器把 backslash_quote、escape_string_warning 和 standard_conforming_strings 复制到自身状态。普通带引号字符串只有在 standard_conforming_strings 为 off 时才进入可处理转义的 xe 规则;显式 E'...' 直接进入该规则。显式 E 字符串在进入 xe 时把 warn_on_first_escape 初始化为 false,因此不会触发这组旧式的首次转义 WARNING;但它仍受 backslash_quote 的 ERROR 检查条件约束,E 前缀不是绕过该条件的通用办法。反斜杠后是单引号时,如果 backslash_quote = off,或安全编码模式遇到仅客户端支持的编码(client-only),就以 ERROR 发出主消息 unsafe use of \' in a string literal,并提示使用成对单引号。
当 escape_string_warning 和每个字符串只警告第一次转义的条件打开时,词法器会分别为 \'、\\ 或其他转义每个字符串发出一次 WARNING。精确主消息是 nonstandard use of \' in a string literal、nonstandard use of \\ in a string literal 和 nonstandard use of escape in a string literal。这些是警告诊断,不是 NOTICE,本身不会中止语句。
报文 {#messages}
ERROR主消息:unsafe use of \' in a string literal;HINT:Use '' to write quotes in strings. \' is insecure in client-only encodings.WARNING主消息:nonstandard use of \' in a string literal;HINT:Use '' to write quotes in strings, or use the escape string syntax (E'...').WARNING主消息:nonstandard use of \\ in a string literal;HINT:Use the escape string syntax for backslashes, e.g., E'\\'.WARNING主消息:nonstandard use of escape in a string literal;HINT:Use the escape string syntax for escapes, e.g., E'\r\n'.
诊断 {#diagnosis}
保留字面量写法和字符位置、是否有 E 前缀、standard_conforming_strings、backslash_quote、escape_string_warning、客户端编码及消息严重性。ERROR 分支会拒绝当前语句,警告分支可能允许语句继续,因此不能只根据“反斜杠”三个字判断结果。
处理 {#response}
嵌入单引号时写成连续两个单引号;确实需要反斜杠时使用明确的 E'...' 语法并固定预期转义语义。如果是 ERROR,显式事务已中止,重试前执行 ROLLBACK 或 ROLLBACK TO SAVEPOINT;自动提交模式下先修正字面量。WARNING 不需要事务恢复,但应优先修正字面量,不要靠隐藏警告或全局改策略来掩盖问题。引用路径不要求重置连接。
版本 {#versions}
锁定目录从 PostgreSQL 8.1.0 记录此条件。引用的扫描器检查条件和精确消息来自 PostgreSQL 18.6 REL_18_6;本次没有运行区域设置或 GUC 案例。
相关 {#related}
来源 {#sources}
src/backend/parser/scan.l#L545-L560
src/backend/parser/scan.l#L706-L720
src/backend/parser/scan.l#L1423-L1459
结构化证据记录保存四个精确主消息、提示、检查条件、严重性和源码/运行边界。
比较版本
SQLSTATE 证据与已记录的运行版本
claims · identity
{
"claim_id": "identity",
"limits": "",
"method": "Read fixed definition.",
"position": 0,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "22P06 is nonstandard_use_of_escape_character in SQLSTATE Class 22."
}claims · error-guard
{
"claim_id": "error-guard",
"limits": "",
"method": "Read the complete xe escape rule and scanner setting copy.",
"position": 1,
"runtime": [],
"sources": [
"src.path.error-guard",
"src.path.scanner-copy"
],
"statement": "For an escape followed by a single quote, the scanner emits ERROR 22P06 when backslash_quote is off, or when safe-encoding mode is used with a client-only encoding. The primary and hint advise doubled quotes."
}claims · warning-guards
{
"claim_id": "warning-guards",
"limits": "",
"method": "Read ordinary and explicit-E literal-mode selection and all three warning branches.",
"position": 2,
"runtime": [],
"sources": [
"src.path.literal-mode",
"src.path.warning",
"src.path.escape-warning"
],
"statement": "For ordinary non-E strings the scanner enters xe only when standard_conforming_strings is off and initializes warn_on_first_escape for warning checks. Explicit E strings enter xe with warn_on_first_escape false, so they avoid this legacy first-escape WARNING while remaining subject to the backslash_quote ERROR guard. With escape_string_warning enabled on the warning path, the scanner emits one WARNING per string for backslash-quote, backslash-backslash, or another escape."
}claims · severity-boundary
{
"claim_id": "severity-boundary",
"limits": "No locale runtime was executed.",
"method": "Read ereport severity at each branch.",
"position": 3,
"runtime": [],
"sources": [
"src.path.error-guard",
"src.path.warning",
"src.path.escape-warning"
],
"statement": "The ERROR rejects the current statement; WARNING is a warning diagnostic and does not by itself abort the statement or explicit transaction."
}claims · history
{
"claim_id": "history",
"limits": "",
"method": "Use catalogue boundary.",
"position": 4,
"runtime": [],
"sources": [
"src.errcodes.18.6"
],
"statement": "The locked catalogue records 22P06 from 8.1.0; that boundary does not prove exact implementation introduction."
}messages · message.error
{
"limits": "",
"message_id": "message.error",
"path": "",
"position": 0,
"raw": {
"hint_template": "Use '' to write quotes in strings. \\' is insecure in client-only encodings.",
"id": "message.error",
"primary_template": "unsafe use of \\' in a string literal",
"severity_source": "ERROR",
"sources": [
"src.path.error-guard"
],
"sqlstate": "22P06"
},
"severity": "ERROR",
"sources": [
"src.path.error-guard"
],
"templates": [
{
"kind": "primary",
"literal": "unsafe use of \\' in a string literal",
"position": 0,
"role": "",
"template": "unsafe use of \\' in a string literal"
},
{
"kind": "hint",
"literal": "Use '' to write quotes in strings. \\' is insecure in client-only encodings.",
"position": 1,
"role": "",
"template": "Use '' to write quotes in strings. \\' is insecure in client-only encodings."
}
]
}messages · message.quote-warning
{
"limits": "",
"message_id": "message.quote-warning",
"path": "",
"position": 1,
"raw": {
"hint_template": "Use '' to write quotes in strings, or use the escape string syntax (E'...').",
"id": "message.quote-warning",
"primary_template": "nonstandard use of \\' in a string literal",
"severity_source": "WARNING",
"sources": [
"src.path.warning"
],
"sqlstate": "22P06"
},
"severity": "WARNING",
"sources": [
"src.path.warning"
],
"templates": [
{
"kind": "primary",
"literal": "nonstandard use of \\' in a string literal",
"position": 0,
"role": "",
"template": "nonstandard use of \\' in a string literal"
},
{
"kind": "hint",
"literal": "Use '' to write quotes in strings, or use the escape string syntax (E'...').",
"position": 1,
"role": "",
"template": "Use '' to write quotes in strings, or use the escape string syntax (E'...')."
}
]
}messages · message.backslash-warning
{
"limits": "",
"message_id": "message.backslash-warning",
"path": "",
"position": 2,
"raw": {
"hint_template": "Use the escape string syntax for backslashes, e.g., E'\\\\'.",
"id": "message.backslash-warning",
"primary_template": "nonstandard use of \\\\ in a string literal",
"severity_source": "WARNING",
"sources": [
"src.path.warning"
],
"sqlstate": "22P06"
},
"severity": "WARNING",
"sources": [
"src.path.warning"
],
"templates": [
{
"kind": "primary",
"literal": "nonstandard use of \\\\ in a string literal",
"position": 0,
"role": "",
"template": "nonstandard use of \\\\ in a string literal"
},
{
"kind": "hint",
"literal": "Use the escape string syntax for backslashes, e.g., E'\\\\'.",
"position": 1,
"role": "",
"template": "Use the escape string syntax for backslashes, e.g., E'\\\\'."
}
]
}messages · message.escape-warning
{
"limits": "",
"message_id": "message.escape-warning",
"path": "",
"position": 3,
"raw": {
"hint_template": "Use the escape string syntax for escapes, e.g., E'\\r\\n'.",
"id": "message.escape-warning",
"primary_template": "nonstandard use of escape in a string literal",
"severity_source": "WARNING",
"sources": [
"src.path.escape-warning"
],
"sqlstate": "22P06"
},
"severity": "WARNING",
"sources": [
"src.path.escape-warning"
],
"templates": [
{
"kind": "primary",
"literal": "nonstandard use of escape in a string literal",
"position": 0,
"role": "",
"template": "nonstandard use of escape in a string literal"
},
{
"kind": "hint",
"literal": "Use the escape string syntax for escapes, e.g., E'\\r\\n'.",
"position": 1,
"role": "",
"template": "Use the escape string syntax for escapes, e.g., E'\\r\\n'."
}
]
}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#L183"
}sources · src.path.guc
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 1,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.guc",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L62"
}sources · src.path.literal-mode
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 2,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.literal-mode",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L545-L560"
}sources · src.path.error-guard
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 3,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.error-guard",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L706"
}sources · src.path.warning
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 4,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.warning",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L1423"
}sources · src.path.escape-warning
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 5,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.escape-warning",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L1450"
}sources · src.path.scanner-copy
{
"commit": "724edf9bde9d356724ad384a2e196edc3c9f80f7",
"docs_url": "",
"kind": "upstream_source",
"location": "",
"path": "src/backend/parser/scan.l",
"position": 6,
"sha256": "bf453f1ae3c22b84fea6f8e8bed4fda476b7cfa49b234efbf92ca228234d0293",
"source_id": "src.path.scanner-copy",
"tag": "REL_18_6",
"url": "https://github.com/postgres/postgres/blob/724edf9bde9d356724ad384a2e196edc3c9f80f7/src/backend/parser/scan.l#L1262"
}来源引用
定义来源
center · PostgreSQL 18 · english-manuals:31426318850b232cfa7dbfcd4344a56decc442f09dc4ea741b7dc72bb61279ac
正文语言: zh-Hans · english-manuals:31426318850b232cfa7dbfcd4344a56decc442f09dc4ea741b7dc72bb61279ac