Cert EspressoLearn. Practise. Find your flow.

A LITTLE FOCUS.
A BIG NEXT STEP.

Your pace. Your space.
Snowflake · SnowPro Core

Semi-Structured Data, FLATTEN, and Unstructured Files

SnowPro Core · Lesson 23 of 27 · 2:50:13

YouTube loads only after you press play. This chapter opens at its timestamp in the full course. Watch on YouTube ↗

Learning with these videos? Subscribe for new courses and exam-style questions.

In this lesson

Prepare for the SnowPro Core Certification exam (COF-C03). In this lesson: the VARIANT type, querying semi-structured data, FLATTEN, and working with unstructured files. Follows Foxglove Apparel, a fictional online clothing retailer. Includes three original practice questions.

Study notes

The text of this lesson, to read at your own pace. Information as of November 2026.

Three shapes of data

Foxglove's data comes in three shapes: order rows with fixed columns, website events in JSON with nested arrays of items, and product photos and supplier PDFs. Each shape needs its own way of storing and querying. Snowflake handles all three on the same platform, with the same SQL.

Structured and semi-structured types

Structured data fits fixed columns, with types such as NUMBER, VARCHAR, DATE, and TIMESTAMP. Semi-structured data goes into a VARIANT, which can hold any value, including an OBJECT or an ARRAY, up to one hundred and twenty-eight megabytes uncompressed. Snowflake loads JSON, Avro, ORC, Parquet, and XML, and it converts the first four into VARIANT values automatically, while PARSE_JSON converts a string. Structured types, such as an ARRAY of integers, an OBJECT with named fields, or a MAP, add fixed types to these containers.

Querying semi-structured data

A colon reaches a first-level element of a VARIANT column, and dots or brackets go deeper, with array positions starting at zero. The column name is not case-sensitive, but element names are, so Customer and customer are two different elements. Extracted values are still VARIANT values, shown in double quotes, so you cast them with two colons, as in NUMBER or STRING. The GET and GET_PATH functions do the same work as the notation.

FLATTEN

FLATTEN is a table function that explodes an ARRAY or an OBJECT into one row per element, usually with LATERAL in the FROM clause. Its output columns include VALUE, INDEX for arrays, KEY for objects, PATH, SEQ, and THIS. When OUTER is set to TRUE, a row whose array is empty or missing still returns one row, with NULL values, while the default drops it. With RECURSIVE set to TRUE, FLATTEN expands every nested level, not only the path you give it.

Storing semi-structured data

You can keep raw documents in a single VARIANT column, or pull the elements you query most into typed columns as you load. A VARIANT stores each value together with its type, so it works in expressions, but a cast makes the type explicit. A null in JSON is stored as a VARIANT null, which is a real value, and not the same as a SQL NULL. And a document larger than about one hundred and twenty-eight megabytes must be split, across rows or columns.

Unstructured files and URLs

Unstructured files, such as images, PDFs, and audio, stay on internal or external stages, and a directory table catalogs them. A scoped URL gives temporary access for twenty-four hours, only to the user who generated it, which suits views and shares, since only roles with privileges on the view get the files. A file URL is permanent, and opening it needs a role with privileges on the stage. A pre-signed URL is an open HTTPS link that needs no authentication, with an expiry time that you choose, which suits reporting tools.

Processing unstructured data

To process the content of files, Python or Java functions and procedures can read staged files directly. The FILE data type, created with TO_FILE, represents a staged file, and some built-in functions accept it. Cortex AI functions, such as AI_PARSE_DOCUMENT, read the text and layout of documents, as lesson nine showed. The results land in tables, as structured or semi-structured data, ready for SQL.

Recap

Let's recap. VARIANT holds any semi-structured value, up to one hundred and twenty-eight megabytes, and structured types add fixed types. A colon, dots, and brackets reach elements, whose names are case-sensitive, and two colons cast the values. FLATTEN turns arrays and objects into rows, using OUTER to keep empty ones and RECURSIVE for every level. Scoped URLs serve one user for a day, file URLs are permanent, and pre-signed URLs are open links. And functions, procedures, and Cortex AI process the content of files.

Quick checks for this lesson

The 3 questions of this lesson, as plain text. The button above runs them with shuffled choices and the reason behind every choice.

  1. Foxglove’s click events hold JSON such as {“Customer”: {“Id”: 42}}. The query SELECT event:customer.id FROM clicks returns NULL on every row. Why?

    • The column name must be in uppercase
    • Element names are case-sensitive
    • Dot notation stops at the first level
    • Values must be cast with ::STRING first
    Show the answer

    Element names are case-sensitive

    Element names are case-sensitive, so customer does not match Customer. “The column name must be in uppercase” is wrong, because the column name is not case-sensitive. “Dot notation stops at the first level” is wrong, because dot notation reaches any level. And “Values must be cast with ::STRING first” is wrong, because casting changes the type of a value, not which element is found.

  2. Each Foxglove order event has an items array; analysts need one row per item, and orders whose array is empty must still appear. Which clause fits?

    • LATERAL FLATTEN(input => event:items, outer => TRUE)
    • LATERAL FLATTEN(input => event:items, recursive => TRUE)
    • SELECT event:items[0] for each order
    • PARSE_JSON(event:items) in the select list
    Show the answer

    LATERAL FLATTEN(input => event:items, outer => TRUE)

    FLATTEN returns one row per item, and OUTER set to TRUE keeps orders with no items, as one row with NULL values. “LATERAL FLATTEN(input => event:items, recursive => TRUE)” expands nested levels, but it still drops the empty arrays. “SELECT event:items[0] for each order” returns only the first item of each order. And “PARSE_JSON(event:items) in the select list” is a function that parses a string into a VARIANT, without creating any rows.

  3. Foxglove’s reporting tool, which cannot sign in to Snowflake, must link to supplier PDFs on a stage, and each link should expire after one hour. Which URL fits?

    • A scoped URL from BUILD_SCOPED_FILE_URL
    • A file URL from BUILD_STAGE_FILE_URL
    • A query on the stage’s directory table
    • A pre-signed URL from GET_PRESIGNED_URL
    Show the answer

    A pre-signed URL from GET_PRESIGNED_URL

    A pre-signed URL needs no authentication, and its expiry time can be set to one hour. “A scoped URL from BUILD_SCOPED_FILE_URL” works only for the user who generated it. “A file URL from BUILD_STAGE_FILE_URL” is permanent, and it needs a role with privileges on the stage. And “A query on the stage’s directory table” lists the files without giving access to them.