2200LERRORTier 2 — Caution✅ HIGH confidencenot an XML document
What this means
SQLSTATE 2200L is raised when an XML-related function or cast receives input that is not a well-formed XML document. A valid XML document must have exactly one root element.
Why it happens
- 1Passing a string with multiple root elements or no root element to an XML function that requires a document
- 2Passing XML content that is well-formed as a fragment but not as a standalone document
How to reproduce
Casting a string with multiple root elements to XML.
SELECT XMLPARSE(DOCUMENT '<a/><b/>'); -- two root elementsFix 1: Wrap content fragments in a single root element
When the input is a fragment rather than a full document.
SELECT XMLPARSE(DOCUMENT '<root><a/><b/></root>');Why this works
Wrapping in a root element produces a valid XML document with exactly one root.
Fix 2: Use XMLPARSE(CONTENT ...) for XML fragments
When the input is a well-formed fragment but not a full document.
SELECT XMLPARSE(CONTENT '<a/><b/>');Why this works
CONTENT mode accepts XML fragments without requiring a single root element.
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 document validation. Stable across versions.
See also
🔗 Related errors
📄 Reference pages