Parameter · Client Connection Defaults / Statement Behavior
xmloption
Sets whether XML data in implicit parsing and serialization operations is to be considered as documents or content fragments.
- Default:
content - Type: enum
- Values: content · document
- Applies: Session (any user)
In plain words
XML can be a full document (exactly one root element) or just a fragment of content (text and several elements). This setting decides which one is expected when text is converted to the xml type without saying.
For DBAs and operators
Affects implicit conversions between character strings and xml: casts to and from xml such as '…'::xml. The explicit forms XMLPARSE(DOCUMENT …) / XMLPARSE(CONTENT …) override it. Equivalent SQL-standard syntax: SET XML OPTION { DOCUMENT | CONTENT }.
content (default) accepts any well-formed content, including documents. document rejects fragments:
ERROR: invalid XML document with DETAIL: line 1: Start tag expected, '<' not found
Pitfall: a dump of a table with fragment values restored into a session with xmloption = document fails. pg_dump handles this, but hand-made loads may not.
How to change it
Any user can change it for their session with SET.