Incident brief
Invalid XML comment
xmlcomment() rejects text that would produce an illegal XML comment, XML comments cannot contain a double hyphen or end with a hyphen.
What lands in your log
ERROR: invalid XML comment
In 10 seconds
- What triggers it
- Call xmlcomment(text) with text that contains '--' or ends with '-'.
- Fix
- Remove or replace '--' sequences (and any trailing '-') in the comment text.
- Proof
- Reproduced on PostgreSQL 18.4 → A single SELECT reproduces SQLSTATE 2200S; the illegal comment text is rejected by xmlcomment().
Fix
What to do right now
Application-level steps for this error.
- Remove or replace '--' sequences (and any trailing '-') in the comment text.
- Sanitize interpolated text before wrapping it in xmlcomment().
-- XML comments cannot contain '--' or end with '-'.
SELECT xmlcomment('build failed');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 comment (2200S) 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 comment content
Check the exact XML shape before applying xmlparse/xmlcomment/xmlpi.
SELECT comment_text,
position('--' in comment_text) > 0 AS contains_forbidden_double_hyphen,
right(comment_text, 1) = '-' AS ends_in_hyphen
FROM (VALUES ('bad--comment'::text)) v(comment_text);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)
2200S → invalid_xml_commentRead the full section on postgresql.org →
Building an illegal XML comment
XML forbids '--' inside a comment, so xmlcomment() on such text raises 'invalid XML comment'.The session continues normally
xmlcomment() failed on its own, outside a transaction block, so there's no lingering state before the next statement.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 xmlcomment(text) with text that contains '--' or ends with '-'.
- 2PostgreSQL checks that the resulting comment would be legal XML.
- 3The illegal comment aborts the statement with SQLSTATE 2200S.
A build note containing a double hyphen was pushed into an XML comment and broke the document generation.
-- The error is self-contained in one statement; no schema is required.
SELECT 'no schema needed' AS setup_note;SELECT xmlcomment('build--failed');SELECT 'ok' AS session_after_error;What PostgreSQL actually returned
setup_note
------------------
no schema needed
(1 row)ERROR: invalid XML comment session_after_error
---------------------
ok
(1 row)xmlcomment() succeeds once the text is a legal comment body.
Without this
Before: '--' in the text aborts
With this, tested
After: clean text produces a comment
- 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.