Infer a schema and create a table from it
INFER_SCHEMA proposes column definitions from staged files. Review that proposal before creating your table.
Understand the idea
Create a separate CSV format with PARSE_HEADER rather than SKIP_HEADER. IGNORE_CASE normalizes inferred column names to uppercase. Inference supports CSV, JSON, Parquet, Avro and ORC; use the appropriate reader.
| Concept | What it means |
|---|---|
| INFER_SCHEMA | Returns names, types, nullability and ordering metadata. |
| GENERATE_COLUMN_DESCRIPTION | Formats the inference as a readable column-definition list. |
| USING TEMPLATE | Creates a table from the inference array. |
| Sampling | Only inspected data informs the proposal. |
A concrete example
The two-column orders.csv suggests ORDER_ID and AMOUNT; it cannot reveal fields arriving next month.
Remember: Inference describes observed structure, not business meaning or a guaranteed future contract.
Explain it step by step · full theory
How to apply it
Create a separate CSV format with PARSE_HEADER rather than SKIP_HEADER. IGNORE_CASE normalizes inferred column names to uppercase. Inference supports CSV, JSON, Parquet, Avro and ORC; use the appropriate reader.
Review all representative files and inferred precision/nullability. A price column sampled only from integers may need an explicitly chosen decimal type for future values. Generating a column description does not execute DDL.
Words used in this lesson
- INFER_SCHEMA
- Returns names, types, nullability and ordering metadata.
- GENERATE_COLUMN_DESCRIPTION
- Formats the inference as a readable column-definition list.
- USING TEMPLATE
- Creates a table from the inference array.
- Sampling
- Only inspected data informs the proposal.
See how it works
Choose a step to explore the idea at your own pace.
Open the interactive explanation
Infer a schema and create a table from it
Understand the input
INFER_SCHEMA proposes column definitions from staged files. Review that proposal before creating your table.
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
- Understand the input
INFER_SCHEMA proposes column definitions from staged files. Review that proposal before creating your table.
- Follow the example
The two-column orders.csv suggests ORDER_ID and AMOUNT; it cannot reveal fields arriving next month.
- Check the outcome
Inference describes observed structure, not business meaning or a guaranteed future contract.
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.
Before running this lesson
Manual examples only. Start with this module’s first lesson to create L2_OBJECTS_LAB.M6_LAB. In each new SQL session select that schema and an authorized warehouse. Later lessons state additional prerequisites. Upload file contents through Snowsight or a supported client; never run CSV as SQL.
Inspect and create a proposed schema
CREATE FILE FORMAT M6_HEADER_CSV TYPE=CSV PARSE_HEADER=TRUE
FIELD_OPTIONALLY_ENCLOSED_BY='"' ERROR_ON_COLUMN_COUNT_MISMATCH=FALSE;
SELECT * FROM TABLE(INFER_SCHEMA(
LOCATION=>'@M6_FILES/base/', FILE_FORMAT=>'M6_HEADER_CSV', IGNORE_CASE=>TRUE));
SELECT GENERATE_COLUMN_DESCRIPTION(ARRAY_AGG(OBJECT_CONSTRUCT(*)), 'table')
FROM TABLE(INFER_SCHEMA(LOCATION=>'@M6_FILES/base/',
FILE_FORMAT=>'M6_HEADER_CSV', IGNORE_CASE=>TRUE));
CREATE TABLE M6_INFERRED USING TEMPLATE (
SELECT ARRAY_AGG(OBJECT_CONSTRUCT(*)) WITHIN GROUP (ORDER BY ORDER_ID)
FROM TABLE(INFER_SCHEMA(LOCATION=>'@M6_FILES/base/',
FILE_FORMAT=>'M6_HEADER_CSV', IGNORE_CASE=>TRUE))
);
DESC TABLE M6_INFERRED;What to expect and why
The table is created with inferred columns but remains empty. Exact inferred numeric precision follows the supplied data; inspect it instead of assuming a fixed result.
Check your understanding
Choose an answer, then check your reasoning. This is practice, not a scored test.
Try it yourself
Why inspect more than one representative file?
Compare your reasoning
A single file may omit optional fields or contain an unrepresentative range of values.
Official sources and curriculum
Module 06 · See module scope