
SQL editor, scheduler, and pipelines in one native Mac app. Daily notes for people who write queries.
Joined October 2026
- Tweets798
- Following169
- Followers49
- Likes999
A query stuck for ten minutes may not be working at all. It could be waiting on a lock. In Postgres, this shows who's stuck and who's blocking:
SELECT pid, pg_blocking_pids(pid) AS blocked_by, left(query, 50)
FROM pg_stat_activity
WHERE cardinality(pg_blocking_pids(pid)) > 0;

ALT Find the blocker. A Postgres query on pg_stat_activity that selects pid, pg_blocking_pids(pid) as blocked_by, and the first 50 characters of the query, filtered to sessions where pg_blocking_pids is not empty. Example result: a waiting UPDATE orders SET status = 'void', blocked by the session holding the lock.
1
7
Alphabetical order puts closed tickets ahead of urgent ones. A CASE in ORDER BY sorts by the order you actually care about:
ORDER BY CASE status
WHEN 'urgent' THEN 1
WHEN 'open' THEN 2
WHEN 'waiting' THEN 3
ELSE 4
END
Any status you didn't list lands at the end.
1
7
Last day of the month in Postgres, without a calendar table:
(date_trunc('month', d) + interval '1 month' - interval '1 day')::date
It steps back one day from the first of next month, so February and leap years come out right without guessing 28, 30, or 31.
1
7
bool_and and bool_or answer the "every" and "any" questions per group in Postgres.
bool_and(paid) is true only if every invoice is paid. bool_or(days_late > 0) is true if any one was late. Both skip NULLs.
getqueryflow.com/?utm_source…
1
32
A recursive CTE can walk a manager chain from one employee up to the top, however many levels there are.
The first SELECT picks the starting row. The second joins each person's manager onto the row before it, and the recursion stops when there's no manager left to find.
5
GitHub repos sit in BigQuery's public data, with a table of which license each one uses.
SELECT license, count(*) AS repos
FROM `bigquery-public-data.github_repos.licenses`
GROUP BY license
ORDER BY repos DESC
Before you run it, which license is first and which is second?
Tuesday 60-second challenge. In Postgres, what do these two return?
SELECT date '2026-11-24' - date '2026-11-01'
SELECT timestamp '2026-11-24' - timestamp '2026-11-01'
Same days on the calendar, but they don't come back as the same type. Guess before you run them.
1
12
Weekly active users isn't the sum of daily active users. Someone who shows up Monday and Tuesday gets counted twice.
SELECT date_trunc('week', ts) AS week,
count(DISTINCT user_id) AS users
FROM events
GROUP BY week
Count distinct over the whole window, not day by day.
7
Bucketing events into 15-minute slots used to take date_trunc plus some math. Since Postgres 14, date_bin does it in one call:
SELECT date_bin('15 minutes', ts, '2026-01-01') AS bucket, count(*)
FROM events
GROUP BY bucket
The third argument sets where buckets line up.
1
13
A running total that starts over every month only needs a PARTITION BY.
SUM(amount) OVER (PARTITION BY date_trunc('month', day) ORDER BY day)
Each month restarts from its first day. Leave out the PARTITION BY and the total keeps climbing across months.
1
13
Your daily orders chart skips the days nobody ordered, because GROUP BY can't group rows that don't exist.
In Postgres, generate the dates first with generate_series, then LEFT JOIN your orders onto them. Count the order id and quiet days show a real 0.
getqueryflow.com/?utm_source…
12
NYC's 311 service requests sit in BigQuery's public data, and every request is tagged with a complaint type.
Which type do you think shows up the most? Noise, heat and hot water, illegal parking, or something else?
Drop your guess before anyone runs the query.
1
1
22











