PostgreSQL supports the XML data type, but XML is usually a poor choice for application document storage. Its text-based representation combines low efficiency with difficult parsing and only marginal human readability. section 3.8
Common production problems include:
- Requiring one root element makes concatenating XML fragments harder because content must be parsed and combined correctly. section 3.8
- Adding namespaces creates collision-handling work, while numeric values can vary textually across locales. section 3.8
- Supporting different escaping rules for text, attributes, comments, and CDATA increases the likelihood of malformed input. section 3.8
- Parsing large XML documents can create memory-allocation problems, requiring a deliberate choice between DOM and SAX or streaming parsers. section 3.8
- PostgreSQL does not validate XML against a DTD and does not support XML Schema or other XML schema languages. section 3.8
A storage-size warning
Casting a property document to XML and measuring it with pg_column_size reports 72 bytes, while the comparable '{"color":0}'::JSON value reports 15 bytes. The exact values depend on the represented content, but the listing makes the storage tradeoff concrete.
Use XML mainly when immutable XML must be copied into the database without querying or manipulating it. For queryable or mutable document data, prefer JSON or JSONB; for exact numeric values, use NUMERIC or another suitable numeric format. section 3.9 section 3.8




