PG
PRO
2200SERRORTier 3 — Handle with care✅ HIGH confidence

invalid XML comment

Category: Data ExceptionVersions: All Postgres versions (XML support must be compiled in)

What this means

SQLSTATE 2200S is raised when an XML comment is syntactically invalid — for example, containing double hyphens (--) within the comment body or not properly closed.

Why it happens

  1. 1XML comment containing -- within the comment body (not at the closing --)
  2. 2Unclosed XML comment (missing -->)

How to reproduce

XML document with an invalid comment.

trigger — this will ERROR
SELECT XMLPARSE(DOCUMENT '<r><!-- bad -- comment --></r>');
ERROR: invalid XML comment

Fix 1: Remove double hyphens from XML comment bodies

When constructing XML with comments programmatically.

fix

Why this works

XML comments may not contain -- in the body. Replace -- with a single hyphen or remove comments from the XML.

Sources

📚 Official docs: https://www.postgresql.org/docs/current/errcodes-appendix.html

🔧 Source ref: Class 22 — Data Exception

Confidence assessment

✅ HIGH confidence

Standard SQLSTATE for XML comment validation. Stable across versions.

See also

📄 Reference pages

XML Functions
⚙️ This error reference was generated with AI assistance and reviewed for accuracy. Examples are provided to illustrate common scenarios and may not cover every case. Always test fixes in a development environment before applying to production. Spotted an error? Suggest a correction →