Create a Snowflake table from CSV headers with typed columns
Recipe ToolsMarketingDatabase
What it does
When the clock triggers every 5 minutes, this automation reads CSV headers and creates a Snowflake table. All columns are set to numeric type except for the timestamp column, which gets a timestamp type instead.
Who it's for
Data and analytics teams who need to set up Snowflake tables from CSV files without manual schema definition.
How teams use this
Automate Snowflake table creation from CSV
Set up a scheduled automation that reads CSV headers and builds a Snowflake table with the correct schema every 5 minutes. The team no longer needs to manually define columns or data types.
Handle multiple timestamp columns
Extend the automation to check for multiple timestamp columns and assign timestamp type to each one. Add a condition that identifies any column name containing time and applies the correct data type.
Support different data types per column
Retarget this automation for a different CSV source that requires text type for names and numeric type for identifiers. Update the column mapping logic to match the new schema requirements.
Alert the team on table creation failure
Add a notification step that sends a message to a Slack channel if the Snowflake table creation fails. Include the error details so the team can troubleshoot immediately.
How it works
- Trigger every 5 minutes. The automation runs on a 5-minute schedule to check for new CSV files and prepare to create or update the Snowflake table.
- Extract CSV headers into a list. Parse the CSV file in Snowflake to pull out all column headers and store them as a variable list for processing.
- Build column definitions with data types. Loop through each header and assign numeric type as the data type, except for the timestamp column which receives timestamp type instead.
- Create the table in Snowflake. Execute the create table statement in Snowflake using the column list and data types defined in the previous step.
- Log the result to job report. Record whether the table was created successfully or if an error occurred in Snowflake, so the team can monitor the automation health.