Which functions can be used to extract values from a VARIANT column by specifying a hierarchy name?
Select TWO.
Correct Answer: A,C
The correct answers are A. GET() and C. GET_PATH() .
Snowflake supports functions for extracting values from semi-structured data stored in a VARIANT, OBJECT, or ARRAY column. GET() and GET_PATH() can retrieve values by specifying keys, indexes, or paths.
Why A is correct:
GET() extracts a value from an object or array. For an object, it can retrieve the value associated with a specified key.
Example:
SELECT GET(src, ' customer ' )
FROM my_table;
Why C is correct:
GET_PATH() extracts a value from semi-structured data using a path expression. This is useful when specifying a hierarchy or nested path.
Example:
SELECT GET_PATH(src, ' customer.name ' )
FROM my_table;
Why the other options are incorrect:
B). TO_JSON() converts a VARIANT value to a JSON string. It does not extract values by hierarchy name.
D). PARSE_JSON() parses a string into a VARIANT. It does not extract an existing nested value.
E). LATERAL FLATTEN expands arrays or objects into rows. It is useful for traversing semi-structured data, but it is not a scalar extraction function that retrieves a value by specifying a hierarchy name.
Official Snowflake documentation reference:
Snowflake documentation describes GET() as a function that extracts a value from an object or array, and GET_PATH() as a function that extracts a value from semi-structured data using a path name.
Reference: Snowflake Documentation - GET; Snowflake Documentation - GET_PATH; Snowflake Documentation - Querying semi-structured data; SnowPro Core Study Guide - Working with Semi- Structured Data.