Preview the file and explain every output column
Preview the parsed fields before loading rows into a table.
Understand the idea
Use the orders_stage created in lesson 5, containing only the supplied orders.csv under incoming/ for this example. It inherits orders_csv_v1. Select an available warehouse that your role can use; querying file contents requires compute, unlike merely thinking through the illustrated result.
| Concept | What it means |
|---|---|
| $1, $2… | Position-based fields from the CSV. |
| Cast | Convert the parsed field into an intended type. |
| Metadata | Connect the result back to the source file. |
A concrete example
If the customer name appears as Asha and the amount field appears as Rao, stop and inspect the enclosure rule. A larger warehouse cannot fix a field-boundary error.
Remember: First inspect field boundaries, then apply names and types. Use metadata for traceability and remember that previewing is not loading.
Explain it step by step · full theory
Check the prerequisites for this exact preview
Use the orders_stage created in lesson 5, containing only the supplied orders.csv under incoming/ for this example. It inherits orders_csv_v1. Select an available warehouse that your role can use; querying file contents requires compute, unlike merely thinking through the illustrated result.
Your role needs access to the parent database and schema, the internal stage and the file format. If setup is incomplete, read the expected result below instead. This website does not connect to Snowflake or execute the SQL.
The first SELECT asks only about field boundaries
s is an alias for the staged source. s.$1 refers to the first parsed CSV field, not the header label. The first query deliberately leaves the fields as parsed values so you can see whether quotes, separators and missing markers were handled correctly.
The FILE_FORMAT option on this staged SELECT explicitly names orders_csv_v1. The stage already has that default, but naming it makes the example’s interpretation visible. Staged SELECT syntax uses FILE_FORMAT =>; do not copy the CREATE STAGE option syntax into this position.
Now turn fields into meaningful typed columns
In the second query, $1 becomes a numeric order ID, $2 becomes the customer name, $3 becomes NUMBER(10,2), and $4 becomes a date with an explicit pattern. AS provides readable output labels. ORDER BY order_id makes the illustrated output order deliberate.
Read order 102 carefully: the empty amount became SQL NULL under the format rules, and the numeric cast preserves that NULL. Order 103 reaches the same result through the textual marker rule. Order 104 becomes 0.00, not NULL.
Keep a route back to the source
METADATA$FILENAME identifies the source file and METADATA$FILE_ROW_NUMBER provides the file row number. These are useful when a later investigation asks where a suspicious record came from. They are source metadata, not fields supplied by our four-column CSV.
A preview is a diagnostic tool. Seeing four correct rows is good evidence for this tiny sample, but previewing a few records from a large delivery is not proof that every record is valid. Module 06 adds the table-load and validation workflow.
Words used in this lesson
- $1
- The first parsed field in a staged CSV record.
- Cast
- An explicit type conversion.
- Source metadata
- Information about the file and row from which a record came.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Preview the file and explain every output column
Locate
Read the supplied file through the stage and explicit format.
Automatic playback is off for reduced motion. Select any step or use Previous and Next. Illustrations explain behavior; they are not live measurements.
Read the complete diagram explanation
- Locate
Read the supplied file through the stage and explicit format.
- Parse
Position-based fields expose the source layout.
- Convert
Names and casts turn source fields into understandable output.
- Trace
Keep file metadata when investigating individual records.
Try the SQL or command
Read → predict → run in your learning environment → compare. You can also learn by reading without an account.
New to SQL? Where to run it and how to read it
A query is a question written in SQL. Snowflake runs it and returns a result table. This website shows examples; it does not connect to your account.
- No account yet? Read and predict the output first. Follow the account and Snowsight lesson when you are ready.
- For SQL practice, use a learning account in Snowsight and select an authorized role and warehouse. A role determines permissions; a warehouse supplies processing power. Follow the example’s database/schema setup when it refers to stored objects.
- Read the entire example, including comments beginning with
--. Run the selected statement or labeled block in the stated order. Examples labeled Python, shell or HTTP belong in that client, not in a SQL editor. - Compare values and row counts with the explained result. If an example deliberately causes an error, follow its rollback and cleanup steps before continuing.
- SELECT / FROM
- Choose the values to return / identify their input.
- VALUES / COLUMN1
- VALUES supplies tiny example rows. COLUMN1 means their first column, COLUMN2 their second.
- AS / WITH
- AS gives a result a readable name. WITH names a temporary query step within one statement.
- NULL / ::
- NULL means missing or unknown. The :: notation converts a value to a named data type.
- Session
- One connection and its settings. Keep related transaction steps in the same session.
- Database.schema.table
- A full address for stored data. It is separate from the warehouse that processes queries.
Need the L2_OBJECTS_LAB setup? Open the first database-object lesson →
Help with common practice errors
- No active warehouse: select a warehouse your role can use. Do not assume you need to create a new one.
- Object missing or not authorized: check the full name, required setup and active role. Ask the account owner for access if needed.
- Object already exists: setup may already have run. Read the current state or choose a fresh lab name consistently; do not add OR REPLACE blindly.
- Different result: check whether an earlier INSERT or UPDATE changed the data. VALUES examples provide their own fresh input for each statement.
Shared orders.csv and internal-stage setup
Four orders, one CSV contract
Every CSV lesson uses this fictional orders.csv. One data record represents one order. The first line is a header; the four remaining lines are data. All amounts use the same fictional currency.
order_id,customer_name,amount,order_date
101,"Asha, Rao",120.50,2025-01-01
102,Ben,,2025-01-02
103,Cara,NULL,2025-01-03
104,Dev,0,2025-01-04Notice the comma inside Asha’s quoted name, Ben’s empty amount, Cara’s literal NULL marker and Dev’s zero. We will follow these exact values from file bytes to parsed fields.
Setup order for optional manual practice
- Select an authorized sandbox database and schema. Keep this context consistent across your client sessions.
- Create orders_csv_v1 using lesson 3, then orders_stage using lesson 5. Use fresh sandbox names; do not replace existing shared objects.
- Save the text above as a UTF-8 file named orders.csv. Upload it with a supported local client or the named-stage upload interface.
- Keep only this sample file under the incoming/ prefix when following the four-row expected results.
- Select an authorized warehouse for the staged SELECT examples. File previews use compute; this website runs no SQL.
The examples assume the required role privileges described in the lessons. The external-stage and JSON examples have their own additional setup and are clearly marked.
Before running this lesson
Internal-stage learning path. Use L2_OBJECTS_LAB.SALES from Module 03, with an authorized role and warehouse. Create orders_csv_v1 in lesson 3, then orders_stage in lesson 5. Save the exact sample as UTF-8 orders.csv. Keep only this file in incoming/ for the illustrated four-row results. Use fresh names if a setup object already exists.
Inspect the parsed fields first
SELECT s.$1, s.$2, s.$3, s.$4
FROM @orders_stage/incoming/
(FILE_FORMAT => 'orders_csv_v1') s
ORDER BY s.$1;What to expect and why
Assume only the supplied file is in this prefix. Four data records remain after the header is skipped. Asha’s name occupies one field even though it contains a comma.
| $1 | $2 | $3 | $4 |
|---|---|---|---|
| 101 | Asha, Rao | 120.50 | 2025-01-01 |
| 102 | Ben | NULL | 2025-01-02 |
| 103 | Cara | NULL | 2025-01-03 |
| 104 | Dev | 0 | 2025-01-04 |
Apply names and intended types
SELECT s.$1::NUMBER AS order_id,
s.$2::VARCHAR AS customer_name,
s.$3::NUMBER(10,2) AS amount,
TO_DATE(s.$4::VARCHAR, 'YYYY-MM-DD') AS order_date
FROM @orders_stage/incoming/
(FILE_FORMAT => 'orders_csv_v1') s
ORDER BY order_id;What to expect and why
The values below are reasoned expected results, not a live execution. The explicit casts check type compatibility; they do not write a destination table.
| ORDER_ID | CUSTOMER_NAME | AMOUNT | ORDER_DATE |
|---|---|---|---|
| 101 | Asha, Rao | 120.50 | 2025-01-01 |
| 102 | Ben | NULL | 2025-01-02 |
| 103 | Cara | NULL | 2025-01-03 |
| 104 | Dev | 0.00 | 2025-01-04 |
Add source breadcrumbs for investigation
SELECT METADATA$FILENAME AS source_file,
METADATA$FILE_ROW_NUMBER AS source_row,
s.$1 AS raw_order_id,
s.$3 AS raw_amount
FROM @orders_stage/incoming/
(FILE_FORMAT => 'orders_csv_v1') s
ORDER BY source_file, source_row;What to expect and why
Use the metadata returned by your actual file rather than hard-coding filenames or row positions. The raw amount here is already parsed: the empty field and NULL marker have already become SQL NULL.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Predict the row count, the full name on order 101 and the number of unknown amounts.
Compare your reasoning
There are four records. Order 101 has the single customer name Asha, Rao. Two amounts are SQL NULL: the empty field on 102 and the text marker on 103. Order 104’s zero remains known.
Official sources and curriculum
Module 05 · See module scope