snowflake.snowpark.functions.to_xml

snowflake.snowpark.functions.to_xml(e: Union[Column, str]) Column[source] (https://github.com/snowflakedb/snowpark-python/blob/v1.26.0/snowpark-python/src/snowflake/snowpark/functions.py#L7731-L7745)

Converts any VARIANT value to a string containing the XML representation of the value. If the input is NULL, the result is also NULL.

Example::
>>> from snowflake.snowpark.types import VariantType, StructField, StructType
>>> from snowflake.snowpark import Row
>>> schema = StructType([StructField("a", VariantType())])
>>> df = session.create_dataframe([Row(a=10), Row(a='test'), Row(a={'a': 10, 'b': 20}), Row(a=[1, 2, 3])], schema=schema)
>>> df.select(to_xml(col("A")).as_("ans")).collect()
[Row(ANS='<SnowflakeData type="INTEGER">10</SnowflakeData>'), Row(ANS='<SnowflakeData type="VARCHAR">test</SnowflakeData>'), Row(ANS='<SnowflakeData type="OBJECT"><a type="INTEGER">10</a><b type="INTEGER">20</b></SnowflakeData>'), Row(ANS='<SnowflakeData type="ARRAY"><e type="INTEGER">1</e><e type="INTEGER">2</e><e type="INTEGER">3</e></SnowflakeData>')]
Copy
Language: English