2200L
PostgreSQLERRORNotableData ExceptionHIGH confidence

not 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
  1. 1Passing a string with multiple root elements or no root element to an XML function that requires a document
  2. 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.

trigger — this will error
trigger — this will error
SELECT XMLPARSE(DOCUMENT '<a/><b/>'); -- two root elements

expected output

ERROR:  invalid XML document

Fix 1

Wrap content fragments in a single root element

WHEN When the input is a fragment rather than a full document.

Wrap content fragments in a single root element
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 When the input is a well-formed fragment but not a full document.

Use XMLPARSE(CONTENT ...) for XML fragments
SELECT XMLPARSE(CONTENT '<a/><b/>');

Why this works

CONTENT mode accepts XML fragments without requiring a single root element.

Sources
Official documentation ↗

Class 22 — Data Exception

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

← All PostgreSQL errors