↑↓ select↵ open⌫ change scopeOpen full search

PG.CENTER connects PostgreSQL documentation, reference, and ecosystem knowledge. Maintained by Pigsty.

Wiki / SQLSTATE

22025 — invalid_escape_sequence

An escape sequence is invalid for its specific consumer. Fixed paths distinguish a LIKE escape argument that is not empty or one character, a LIKE pattern ending in an escape character, a regular-expression translation escape argument with the same length rule, and malformed \u/\U Unicode escapes.

English manual coverage begins with PostgreSQL 8.1. Source history and runtime observations have their own recorded version boundaries.

Reading PG 18·Select a recorded version

aliases
Unknown
class name
Data Exception
condition name
invalid_escape_sequence
lang
en
sqlstate
22025

Definition PG 18

22025

At a glance {#at-a-glance}

An escape sequence is invalid for its specific consumer. Fixed paths distinguish a LIKE escape argument that is not empty or one character, a LIKE pattern ending in an escape character, a regular-expression translation escape argument with the same length rule, and malformed \u/\U Unicode escapes.

Representative messages {#messages}

The representative consumers use these primary texts and hint:

| Consumer / guard | Primary and hint | | --- | --- | | LIKE or SQL regular-expression translation escape length | invalid escape string; HINT: Escape string must be empty or one character. | | LIKE pattern with a trailing escape | LIKE pattern must not end with escape character | | malformed scanner Unicode escape | invalid Unicode escape; HINT: Unicode escapes must be \uXXXX or \UXXXXXXXX. |

Meaning {#meaning}

22025 is emitted by consumer-specific escape guards. LIKE requires its ESCAPE string to be empty or one character and rejects a pattern ending with the escape character. The SQL regular-expression translation helper applies the same empty-or-one-character rule to its escape argument. The core scanner reports malformed Unicode escape syntax with the \uXXXX/\UXXXXXXXX hint. These are distinct from 22019’s escape-character semantics and 2200C’s SIMILAR separator overflow; a regexp_replace option or start/occurrence parameter is a 22023 parameter-validation path instead.

Diagnosis {#diagnosis}

Identify the consumer before editing backslashes: LIKE escape argument, LIKE pattern, SQL regular-expression translation, or an extended string literal’s Unicode scanner. Check whether the escape value is an empty string or one character, whether the LIKE pattern ends after an escape, and whether a Unicode escape has exactly the required \u/\U width. Do not call every regular-expression replacement or SIMILAR syntax error 22025; use the SQLSTATE and primary message actually reported.

Response {#response}

Provide the escape string and pattern required by the named consumer, preserving an intentional empty string as empty rather than SQL NULL. For malformed Unicode syntax, use \uXXXX or \UXXXXXXXX as required by the scanner. If an ERROR occurred in an explicit transaction, roll back or roll back to the existing savepoint before retrying; autocommit can retry the corrected statement.

Versions {#versions}

The locked catalogue records this condition from 7.4; the fixed source paths here are PostgreSQL 18.6. No natural runtime observation is claimed for this page.

Related {#related}

22019, 2200C, 22023

Sources {#sources}

LIKE guards are in src/backend/utils/adt/like_match.c#L159-165 and #L439-449; the SQL regular-expression translation escape-length guard is src/backend/utils/adt/regexp.c#L793-805; malformed Unicode escape syntax is in src/backend/parser/scan.l#L697-704. The structured evidence record retains the exact primaries, hint, and consumer boundaries; no natural runtime was run.

Compare versions

SQLSTATE evidence and recorded runtime versions

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"
}

Source references

Full definition and evidence JSON

Definition sources

center · PostgreSQL 18 · english-manuals:533233a45112ea029b9088666c41ae8f6bdfbdfbcd94143492a681068c647492

Text language: en · english-manuals:533233a45112ea029b9088666c41ae8f6bdfbdfbcd94143492a681068c647492