Testing queries in Snowflake means running safe, scoped executions that confirm logic, performance, and data quality before production use.
Testing prevents costly full-table scans, wrong updates, and surprise credit usage. It ensures your SQL does what you expect on a small dataset before you expose dashboards or pipelines to end-users.
Use SELECT ... LIMIT n
to fetch a sample. Combine it with an ordered column to see edge cases first or last.
Common Table Expressions (WITH
) let you break complex statements into readable blocks you can SELECT
from individually for step-by-step checks.
CREATE TEMPORARY TABLE
stores intermediate results for the current session only. They auto-drop, enabling ad-hoc joins and aggregations without cluttering the schema.
Run EXPLAIN USING TEXT <your_query>
to inspect the optimizer plan. Look for large partitions or unnecessary scans before shipping code.
Query SNOWFLAKE.ACCOUNT_USAGE.QUERY_HISTORY
or INFORMATION_SCHEMA.QUERY_HISTORY
by query_id
to compare elapsed time, scanned bytes, and credits consumed across test iterations.
Always limit rows, filter to recent dates, use SAMPLE
for randomness, and grant least-privilege roles. Tag test runs with comments like -- test: cart abandonment funnel v2
for auditability.
Yes. Wrap them in a transaction (BEGIN
) and issue ROLLBACK
after verification, or copy target rows into a temporary table first.
No. EXPLAIN only shows the optimizer plan and does not execute the query, so it uses zero warehouse compute.
Store test cases in a SQL file and run them in CI using SnowSQL or the Python connector. Compare expected vs. actual results and fail the build on mismatches.