XML data type and functions EARLY ACCESS
Synopsis
The XML data type stores Extensible Markup Language (XML) documents. YSQL fully supports the PostgreSQL XML implementation, including:
- XML data type for storing well-formed XML documents
- XML construction functions for building XML fragments
- XPath functions for querying XML documents
- XML predicates for testing document structure
- XMLTABLE construct for extracting tabular data from XML
- XML schema mapping functions for converting between tables and XML
For a comprehensive reference of all XML functions, see the PostgreSQL XML documentation.
Data type specification
type_specification ::= xml
Functions and operators
The following key XML functions are supported:
XML construction
xmlcomment(text): Constructs an XML commentxmlconcat(xml, ...): Concatenates XML fragmentsxmlelement(name, ...): Constructs an XML elementxmlattributes(...): Specifies attributes for an XML elementxmlforest(...): Constructs a forest of XML elementsxmlpi(name, text): Constructs an XML processing instructionxmlroot(xml, ...): Modifies the root node of an XML document
XML parsing and serialization
xmlparse(content | document text): Parses a text string into XMLxmlserialize(content | document xml as type): Converts XML to text
XPath and XML queries
xpath(xpath_expr, xml_doc, [namespaces]): Evaluates XPath expressionsxpath_exists(xpath_expr, xml_doc): Tests if XPath expression matchesxmlexists(xpath_expr PASSING [BY REF] xml_doc): Alternative XPath test syntaxXMLTABLE(...): Converts XML to tabular form
Aggregation
xmlagg(xml [ORDER BY ...]): Aggregates multiple XML values
Validation
xml_is_well_formed(text): Tests if text is well-formed XMLxml_is_well_formed_document(text): Tests if text is a well-formed XML documentxml_is_well_formed_content(text): Tests if text is well-formed XML content
XML predicates
IS DOCUMENT: Tests if XML value is a well-formed documentIS NOT DOCUMENT: Tests if XML value is not a document
XML schema mapping
Functions to convert between tables and XML are as follows:
table_to_xml(table, nulls, tableforest, targetns)table_to_xmlschema(table, nulls, tableforest, targetns)table_to_xml_and_xmlschema(table, nulls, tableforest, targetns)query_to_xml(query, nulls, tableforest, targetns)query_to_xmlschema(query, nulls, tableforest, targetns)query_to_xml_and_xmlschema(query, nulls, tableforest, targetns)cursor_to_xml(cursor, count, nulls, tableforest, targetns)cursor_to_xmlschema(cursor, nulls, tableforest, targetns)schema_to_xml(schema, nulls, tableforest, targetns)schema_to_xmlschema(schema, nulls, tableforest, targetns)schema_to_xml_and_xmlschema(schema, nulls, tableforest, targetns)
For the full reference and detailed descriptions of all XML functions, see the PostgreSQL XML Functions documentation.
See also
For comprehensive examples and guided tutorials on using XML in YSQL, including:
- Constructing XML documents
- Querying XML with XPath
- Converting between tables and XML
- Handling namespaces
See XML support in YSQL.