PARSE_XML
functionsupportedCore SQL functionsInterprets an input string as an XML document, producing an OBJECT value. If the input is NULL, the output is NULL.
Syntax
supportedpartialnot supportednot scored
PARSE_XML( <string_containing_xml> [ , <disable_auto_convert> ] )
PARSE_XML( STR => <string_containing_xml>
[ , DISABLE_AUTO_CONVERT => <disable_auto_convert> ] )
Parameters
| Name | Required | Description |
|---|---|---|
string_containing_xml OR STR => string_containing_xml | required | Specify an expression that evaluates to a VARCHAR value that contains valid XML. |
disable_auto_convert OR DISABLE_AUTO_CONVERT => disable_auto_convert | optional | A Boolean expression that specifies whether or not the function should attempt to convert numeric and Boolean values in string_containing_xml to Snowflake data types. (For details about this conversion, see Usage Notes below.) If you don’t want the function to convert these values, set this argument to TRUE. This setting has an effect that is similar to the DISABLE_AUTO_CONVERT parameter in CREATE FILE FORMAT. If you want the function to convert these values, set this argument to FALSE or omit this argument. Default: FALSE |
Returns
The data type of the returned value is OBJECT. The OBJECT contains an internal representation of the XML.
Usage notes
- When you mix arguments by position and by name, all of the positional arguments must come before all of the named arguments.
- When you specify an argument by name, you can’t use double quotes around the argument name.
- The content of every element in XML documents is text. PARSE_XML attempts to convert some XML data from text to native (Snowflake SQL). For more information, see SQL data types reference. NUMERIC and BOOLEAN: PARSE_XML attempts to convert obviously numeric and Boolean values to the native representation in a way that printing these values back produces textually identical results. For example, when parsing decimal numbers, PARSE_XML attempts to preserve exactness of the representation by treating 123.45 as NUMBER(5,2), not as a DOUBLE. However: Numbers in scientific notation (i.e. 1.2345e+02) or numbers that cannot be stored as fixed-point decimals due to range or scale limitations are stored as DOUBLE.
- If the content of an XML element is a number with digits after the decimal point, then PARSE_XML might truncate trailing zeros.
- If you do not want the function to perform this conversion, pass TRUE for the disable_auto_convert argument.
- TIMESTAMP, DATE, TIME, BINARY: Because XML doesn’t represent values such as TIMESTAMP, DATE, TIME, or BINARY natively, these have to be represented as strings in XML. PARSE_XML doesn’t automatically recognize these values. They are retained as strings, so convert the values from strings to native SQL data types if needed.
- XML attributes are an unordered collection of name/value pairs. The PARSE_XML function doesn’t necessarily preserve order. For example, converting text to XML and back to text might result in a string that contains the original information in a different order.
- You might see changes in whitespace between elements when converting from string to XML.
- When PARSE_XML is used to insert numeric values into a VARIANT column that are a mix of integers (for example, INT or INTEGER) and values in decimal notation (for example, NUMBER or FLOAT), the function might add trailing zeros to the values. The following example uses PARSE_XML to insert a mix of integer values and values in decimal notation into a VARIANT column: Copy code CREATE OR REPLACE TABLE test_xml_table(xmlcol VARIANT); INSERT INTO test_xml_table ( SELECT PARSE_XML($1) FROM VALUES ('<c>3.1</c>'), ('<e>2</e>'), ('<b>0.123</b>')); Query the table: Copy code SELECT * FROM test_xml_table; +--------------+ | XMLCOL | |--------------| | <c>3.100</c> | | <e>2.000</e> | | <b>0.123</b> | +--------------+ The output shows that trailing zeros were added to the values in the first two rows.