22P06
PostgreSQLWARNINGCriticalData ExceptionHIGH confidence

nonstandard use of escape character

What this means

SQLSTATE 22P06 is a Postgres-specific warning raised when a string literal uses a backslash escape (e.g., \n, \t) in a context where standard_conforming_strings is ON, making the backslash a literal character rather than an escape. This indicates portability risk.

Why it happens
  1. 1Using escape sequences like \n or \t in a regular string literal when standard_conforming_strings = on
  2. 2Code written for old Postgres versions (before 9.1) that used backslash escapes in ordinary string literals
How to reproduce

Using \n in a plain string literal with standard_conforming_strings = on.

trigger — this will error
trigger — this will error
SELECT 'Hello\nWorld'; -- \n is literal backslash+n, not newline

expected output

WARNING:  nonstandard use of \\  in a string literal

Fix 1

Use escape string syntax (E prefix) when you need escape sequences

WHEN When the string genuinely requires escape sequences like \n or \t.

Use escape string syntax (E prefix) when you need escape sequences
SELECT E'Hello\nWorld'; -- E prefix enables escape processing

Why this works

The E prefix explicitly enables escape processing regardless of standard_conforming_strings, making the intent clear and portable.

Fix 2

Use dollar-quoting for strings with backslashes

WHEN When the backslash is intended as a literal character.

Use dollar-quoting for strings with backslashes
SELECT $Hello\World$;

Why this works

Dollar-quoted strings treat backslashes literally and suppress this warning.

What not to do

Set standard_conforming_strings = off to suppress the warning

This is a deprecated mode and will be removed. Fix the string literals instead.

Version notes
Postgres 9.1+

standard_conforming_strings defaults to ON. Escape sequences in plain strings are deprecated.

Sources
Official documentation ↗

Class 22 — Data Exception (Postgres-specific)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All PostgreSQL errors