FOR_XML_UDF (OBJECT, VARCHAR, VARCHAR)

Important Notice: Migration of Documentation Website

Please be advised that our documentation website is currently undergoing a migration to a new platform. To ensure you have access to the most up-to-date information, we kindly request that you visit our new documentation website located at:

Official Snowflake Snowconvert Documentation

For any immediate assistance or if you encounter any issues, please contact our support team at [email protected].

Thank you for your understanding.

Definition

This user-defined function (UDF) converts an object to XML.

FOR_XML_UDF(OBJ OBJECT, ELEMENT_NAME VARCHAR, ROOT_NAME VARCHAR)

Parameters

OBJ OBJECT

Object to be converted.

ELEMENT_NAME VARCHAR

Element name to be given the object.

ROOT_NAME VARCHAR

The root name for XML.

Returns

Returns a varchar in the format of XML.

Usage example

Input:

SELECT
FOR_XML_UDF(OBJECT_CONSTRUCT('id', 1, 'name', 'David'), 'employee', 'employees');

Output:

<employees>
    <employee type="OBJECT">
        <id type="INTEGER">1</id>
        <name type="VARCHAR">David</name>
    </employee>
<employees>

Last updated