Challenge - 5 Problems
Snowflake SELECT Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ service_behavior
intermediate2:00remaining
Understanding the output of a SELECT with DATE_TRUNC
What is the output of this query when run on 2024-06-15 14:35:20?
SELECT DATE_TRUNC('month', '2024-06-15 14:35:20'::TIMESTAMP) AS truncated_date;Snowflake
SELECT DATE_TRUNC('month', '2024-06-15 14:35:20'::TIMESTAMP) AS truncated_date;
Attempts:
2 left
💡 Hint
DATE_TRUNC cuts off smaller parts of the date to the start of the specified part.
✗ Incorrect
DATE_TRUNC('month', timestamp) returns the first day of the month at midnight for the given timestamp.
🧠 Conceptual
intermediate2:00remaining
Effect of TRY_CAST on invalid data
What will be the result of this query?
SELECT TRY_CAST('abc' AS INTEGER) AS result;Snowflake
SELECT TRY_CAST('abc' AS INTEGER) AS result;Attempts:
2 left
💡 Hint
TRY_CAST returns NULL instead of error when conversion fails.
✗ Incorrect
TRY_CAST returns NULL when the cast fails instead of raising an error.
❓ Configuration
advanced2:30remaining
Using LATERAL FLATTEN to extract array elements
Given a table with a VARIANT column named data containing JSON arrays, which query correctly extracts each element as a separate row?
Assume table name is events and column is data.
Options:
Assume table name is events and column is data.
Options:
Snowflake
SELECT value FROM events, LATERAL FLATTEN(input => data);Attempts:
2 left
💡 Hint
LATERAL FLATTEN is used with FROM clause and input parameter.
✗ Incorrect
Option C uses correct syntax: LATERAL FLATTEN with input => data in FROM clause to extract array elements.
❓ security
advanced2:00remaining
Preventing SQL injection with Snowflake functions
Which Snowflake function helps safely handle user input to prevent SQL injection when constructing dynamic SQL queries?
Attempts:
2 left
💡 Hint
This function safely treats input as an object name, not code.
✗ Incorrect
IDENTIFIER() safely treats input as an object identifier, preventing injection in dynamic SQL.
❓ Architecture
expert3:00remaining
Optimizing query performance with clustering keys
You have a large Snowflake table frequently queried by a date column. Which approach best improves query performance for date range filters?
Attempts:
2 left
💡 Hint
Clustering keys physically organize data to speed up range queries.
✗ Incorrect
Clustering keys organize data on disk by specified columns, improving performance on range queries like date filters.