
Answer-first summary for fast verification
Answer: source_column:elements[0].name
The question asks how to extract the 'name' from the first element of the 'elements' array in a JSON document stored in a VARIANT column. In Snowflake, to access elements in semi-structured data stored in VARIANT columns, you use a colon (:) between the column name and the first-level element, followed by bracket notation with zero-based indexing for arrays, and dot notation for nested fields. Therefore, the correct syntax is 'source_column:elements[0].name', which corresponds to option D. Option A uses incorrect dot notation for the first-level element and incorrect bracket notation indexing. Option B also uses incorrect dot notation for the first-level element. Option C uses the correct colon notation but incorrect bracket notation indexing (elements[1] would refer to the second element, not the first). The community discussion, with 83% selecting D and detailed comments explaining the correct syntax for traversing semi-structured data in Snowflake, supports D as the correct answer.
Author: LeetQuiz Editorial Team
Ultimate access to all questions.
SELECT source_column:elements[0].name::STRING AS first_name
FROM your_table;
SELECT source_column:elements[0].name::STRING AS first_name
FROM your_table;
A
source_column.elements[1]:name
B
source_column.elements[0]:name
C
source_column:elements[1].name
D
source_column:elements[0].name
No comments yet.