SQLSTATE 22025Severity lowLab verified

Incident brief

Invalid LIKE ESCAPE string

The ESCAPE clause of LIKE accepts an empty string or exactly one character; a multi-character escape string raises this data exception.

What lands in your log

ERROR: invalid escape string

Reproduced on PostgreSQL 18.4Verified 2026-07-24 (isolated lab, PostgreSQL 18.4)Verified against PostgreSQL 18.4 in an isolated lab environment

In 10 seconds

What triggers it
Write a LIKE ... ESCAPE '<str>' where the escape string is longer than one character.
Fix
Use a single-character escape string, or an empty string to disable escaping.
Proof
Reproduced on PostgreSQL 18.4 → A single SELECT reproduces SQLSTATE 22025; the over-long escape string is rejected with a hint about the allowed length.

Fix

What to do right now

Application-level steps for this error.

  • Use a single-character escape string, or an empty string to disable escaping.
  • If the escape value is dynamic, validate its length before building the LIKE expression.
Fix SQL
-- ESCAPE takes one character, or '' to disable escaping.
SELECT 'x' LIKE 'x' ESCAPE '';

Connected

Everything this error touches

Every page this SQLSTATE connects to: the concept that explains it, the runbooks that fix it, the parameters you tune to prevent it, and the sibling errors it travels with. All real cross-references. Jump straight in, or open the full interactive map.

Open in the interactive map →

Verification

PG 18.4
Last verified
2026-07-24 (isolated lab, PostgreSQL 18.4)
Verification scope
Verified against PostgreSQL 18.4 in an isolated lab environment
Audit status
reviewed
ShareLinkedInX

Went further?

Pro unlocks the second lab proof

Free page stops the bleeding. Pro adds the operational test, SQLSTATE audit, and deeper evidence, same error, more certainty.

FollowSubstackLinkedInnew errors · lab notes · hiring loops