Incident brief
Invalid XML content (CONTENT)
XMLPARSE(CONTENT ...) still requires well-formed markup; an unclosed tag raises this data exception with a DETAIL about the premature end of data.
What lands in your log
ERROR: invalid XML content
In 10 seconds
- What triggers it
- Call XMLPARSE(CONTENT '<...>') with content that has an unclosed tag.
- Fix
- Close every tag so the fragment is well-formed.
- Proof
- Reproduced on PostgreSQL 18.4 → A single SELECT reproduces SQLSTATE 2200N; the unclosed <total> tag is rejected as invalid content.
Fix
What to do right now
Application-level steps for this error.
- Close every tag so the fragment is well-formed.
- Build the fragment with a serializer instead of string assembly.
-- Provide well-formed XML content.
SELECT XMLPARSE(CONTENT '<order><total>10</total></order>');For this error
See this error live on the server
Run these against the affected instance to confirm the diagnosis before you act.
Invalid XML content (CONTENT) (2200N) is statement-local: PostgreSQL does not retain the rejected value after the statement ends. Capture the exact bound value and statement position in application/server logs, then run this targeted validation before retrying.
Validate XML content form
Check the exact XML shape before applying xmlparse/xmlcomment/xmlpi.
SELECT xml_is_well_formed_content('<a/><b/>') AS valid_content;Why it happens
What PostgreSQL is telling you
The mechanism behind the error, grounded in the official manual, not paraphrased.
PostgreSQL 18 Documentation, Appendix A. PostgreSQL Error Codes (Table A.1, Class 22, Data Exception)
2200N → invalid_xml_contentRead the full section on postgresql.org →
Parsing an unterminated XML fragment
The <total> tag is never closed, so libxml reports 'Premature end of data' and PostgreSQL raises 'invalid XML content'.The session continues normally
Because the XML parse failed outside an explicit transaction, session B's next statement runs as if nothing happened.Reproduce & verify
A real, single-session PostgreSQL reproduction
A literal transcript of SQL run against a live PostgreSQL instance in an isolated lab. The commands below are exactly what was executed.
- 1Call XMLPARSE(CONTENT '<...>') with content that has an unclosed tag.
- 2PostgreSQL validates the fragment via libxml.
- 3The premature end aborts the statement with SQLSTATE 2200N.
A template emitted an XML fragment that dropped a closing tag, and CONTENT parsing failed on it.
-- The error is self-contained in one statement; no schema is required.
SELECT 'no schema needed' AS setup_note;SELECT XMLPARSE(CONTENT '<order><total>');SELECT 'ok' AS session_after_error;What PostgreSQL actually returned
setup_note
------------------
no schema needed
(1 row)ERROR: invalid XML content
DETAIL: line 1: Premature end of data in tag total line 1
<order><total>
^ session_after_error
---------------------
ok
(1 row)The same XMLPARSE(CONTENT ...) succeeds once every tag is closed.
Without this
Before: an unclosed tag aborts the parse
With this, tested
After: closed tags parse cleanly
- A second operational test: exact SQL, raw output, measured result, and engineer notes
Card required. Cancel before day 7 and you are not charged.
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.
Verification
- 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
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.