Reference

SQL & Redis

SQLite, PostgreSQL, Snowflake and Redis syntax, queries and everyday operations.

Scope and conventions

SQL examples name their database and assume the sample schema where indicated. Redis examples are native redis-cli commands, with optional Search/JSON features labeled. Run independent examples in your own scratch database; driver binding syntax and transaction guarantees differ.

Analytical models

Recognize a transformation model and its dependencies

SQLite

dbt is a separate transformation tool, not SQLite SQL syntax. SQLite adapters are separate integrations; the SQLite browser bench does not render Jinja templates. A plain SQL view/CTE can express a related transformation without supplying a dbt project contract.

Different native mechanism; no interchangeable statement is implied.

Different native mechanism; no interchangeable operation is implied.

Recognize incremental processing and data checks

SQLite

An incremental data workflow must define its key, late-change window, replay and reconciliation behavior. A WHERE cutoff alone does not guarantee that old corrections or deletions are incorporated. The browser query bench does not run dbt materializations.

Different native mechanism; no interchangeable statement is implied.

Different native mechanism; no interchangeable operation is implied.

Bucket events into a daily time series

SQLite

Truncate each timestamp to its bucket with date() for days or strftime for other formats, then GROUP BY the bucket. A GROUP BY alone leaves out days with no events. To fill the gaps, generate the full calendar with a recursive CTE and LEFT JOIN the events to it, counting a column from the event side so empty days count 0. date(ts, 'weekday 0', '-6 days') gives the Monday that starts the week. SQLite date functions work in UTC unless given the 'localtime' modifier. In practice: store timestamps as UTC ISO-8601 text or Unix seconds, and bucket in the time zone the report is for.

Fragment

SQLite · Bucket events into a daily time series
Follow appearance
GitHub Light
GitHub Dark
Rosé Pine
Catppuccin Mocha
VS Code Dark+
WITH events(happened_at) AS (VALUES
  ('2026-10-01 09:15:00'), ('2026-10-01 17:40:00'),
  ('2026-10-03 08:05:00')
),
days(day) AS (
  SELECT date('2026-10-01')
  UNION ALL
  SELECT date(day, '+1 day') FROM days WHERE day < '2026-10-03'
)
SELECT d.day, count(e.happened_at) AS events
FROM days AS d
LEFT JOIN events AS e ON date(e.happened_at) = d.day
GROUP BY d.day
ORDER BY d.day;
-- 2026-10-01|2
-- 2026-10-02|0
-- 2026-10-03|1

Self-contained SQLite query.