Snowflake guide

Turn questions into Snowflake SQL.

Snowflake separates data access from compute, and its SQL has useful shortcuts for analytics. Name the database, schema, warehouse and business time zone in your setup and review.

Try TTSQL free

Before connecting Snowflake

TTSQL's Snowflake adapter uses Snowflex through ODBC. The deployment needs Erlang ODBC and an installed Snowflake ODBC driver. Supply the account, username, password and database; configure the appropriate warehouse, schema and role for your environment.

Confirm that the selected role can use the warehouse and read the intended tables. An available SQL dialect does not imply that the hosted deployment's driver or your account's authentication method has been configured. The current adapter is configured around username/password credentials; do not assume a key-pair or OAuth setup is interchangeable.

Give the prompt the right dialect and context

Use database.schema.table when the session defaults could be ambiguous. Unquoted Snowflake identifiers resolve in uppercase; double quotes preserve exact case. String literals use single quotes.

Distinguish TIMESTAMP_NTZ, TIMESTAMP_LTZ and TIMESTAMP_TZ. These examples assume UTC values stored without a time zone, as TIMESTAMP_NTZ. A local-time timestamp can change reporting boundaries with the session time zone.

Schema used in these examples

customers(id INTEGER PRIMARY KEY, name TEXT, country TEXT); orders(id INTEGER PRIMARY KEY, customer_id INTEGER REFERENCES customers(id), ordered_at TIMESTAMP, status TEXT, total DECIMAL(12,2)). Each order has one customer. total is the order amount in a single reporting currency; paid means recognized revenue in this teaching dataset. Timestamps use UTC. These are example tables, not tables TTSQL creates.

Translate TEXT and TIMESTAMP to equivalent column types for your engine. Use your own database, schema and table qualifiers. Each example states its reporting grain and sorting rule.

Review these Snowflake details

A small result limit does not mean small warehouse work. Review joins, filters and query profiles for large reporting scans, and choose a warehouse appropriate to the workload.

QUALIFY is a Snowflake-supported clause rather than portable ANSI SQL. When moving this query to PostgreSQL or MySQL, place the window expression in a CTE or subquery and filter it outside.

Generate, review, then choose whether to run

Select the matching database type and confirm your project's schema context before generating. Review the returned SQL against the schema and the metric you intended. A successful connection test does not prove that every table or operation is authorized.

TTSQL's POST /api/v1 endpoint generates SQL and returns executed: false. Query execution is a separate manual Run action in the workspace, subject to the configured connection and policies. The examples below are educational SELECT statements, not live results from your database.

Official Snowflake references

Check your engine version and account configuration when adapting a function or connection setting.

Worked SQL examples

Read the sample schema and assumptions alongside each query. Adapt names, dates, and definitions to your own database before running SQL.

01 / Snowflake SQL

Bucket paid revenue by month

Show paid revenue by month in stored timestamps, with month-start dates in ascending order.

SELECT DATE_TRUNC('MONTH', ordered_at)::DATE AS month,
       SUM(total) AS revenue
FROM orders
WHERE status = 'paid'
GROUP BY 1
ORDER BY 1;

DATE_TRUNC truncates to the month and ::DATE gives a date-valued label. The bucket does not manufacture zero-revenue months. Join a calendar dimension if those rows are part of the reporting contract.

02 / Snowflake SQL

Filter the latest row with QUALIFY

Return each customer's latest paid order, using the greatest order ID to resolve timestamp ties. Sort by customer ID.

SELECT customer_id, id, total
FROM orders
WHERE status = 'paid'
QUALIFY ROW_NUMBER() OVER (
  PARTITION BY customer_id ORDER BY ordered_at DESC, id DESC
) = 1
ORDER BY customer_id;

QUALIFY filters window-function results after WHERE and window evaluation. It removes the need for a wrapping subquery. WHERE still runs first, so this selects the latest paid order, not the latest order only when that order happens to be paid.

03 / Snowflake SQL

Count status conditions with COUNT_IF

For customers with any order, show paid and cancelled order counts, including zero counts. Sort by customer ID.

SELECT customer_id,
       COALESCE(COUNT_IF(status = 'paid'), 0) AS paid_orders,
       COALESCE(COUNT_IF(status = 'cancelled'), 0) AS cancelled_orders
FROM orders
GROUP BY customer_id
ORDER BY customer_id;

COUNT_IF expresses a condition directly. COALESCE makes the requested zero-count behavior explicit when the aggregate returns NULL for no qualifying records. It still does not add customers who are absent from orders.

Answers before you connect a database.

Does selecting Snowflake guarantee a working database connection?

No. SQL generation uses the project dialect and schema, while connection and execution also depend on deployment prerequisites, credentials, network access and database permissions. Complete the prerequisites described in this guide.

Does the TTSQL API execute Snowflake queries?

No. POST /api/v1 generates SQL and returns executed: false. Review the query; a separate manual Run action is available in the workspace when the connection and policies allow it.

Bring your next question to TTSQL.

Start with one PostgreSQL project and 20 free requests a day. Explore your data, build a report, or integrate the API.