On 24.01.25 13:48, Pavel Stehule wrote: > Lot of users use XML functions without XMLDOCUMENT now. The doc should to > help with a reply to question where and when I need (I can) use this > function. This should > be in context of Postgres where every XML expr returns XML value, so > sentence > creates an XML value from XML expression is still very confusing > > What some like > > "SQL/XML introduces XMLDOCUMENT function to returns a document node > from XML tree of some XML value. > This has not any sense (because XML in Postgres is always materialized > to string) in PostgreSQL implementation of XML, and the function just > returns > input value". Or some like that.
I see. I tried to incorporate your suggestion in the text:
In the SQL/XML specification, the XMLDocument (X030) function is designed to return a document node from a given XML value expression. Since PostgreSQL handles XML values as materialized strings rather than tree structures, this function does not produce a document node structure but instead returns the validated input <type>xml</type> value as-is. The input <type>xml</type> value can include any valid XML content, such as elements, text, or a mixture of both. This function does not require the input to have a single root element and does not wrap the result in one. Validation of the <type>xml</type> input value depends on the current <xref linkend="guc-xmloption"/> setting. If the input <type>xml</type> value is NULL, the function returns NULL. This function ensures compatibility with the SQL/XML specification, making it particularly useful when migrating SQL queries from other database systems that also implement this standard.