QueryFlow (@getQueryFlow) header
QueryFlow (@getQueryFlow) profile picture

SQL editor, scheduler, and pipelines in one native Mac app. Daily notes for people who write queries.

Joined October 2026
Three ways to number tied rows, same scores: row_number(): 1, 2, 3, 4 rank(): 1, 1, 3, 4 dense_rank(): 1, 1, 2, 3 rank leaves a gap after a tie. dense_rank doesn't. row_number breaks the tie arbitrarily unless you add a tiebreaker to ORDER BY.
1
3
When you only need to know whether a row exists, ask that directly. count(*) > 0 counts every match first. EXISTS can stop at the first one: SELECT EXISTS ( SELECT 1 FROM orders WHERE customer_id = 42 ); Same true or false, and less work when there are lots of matches.
6
SELECT * in a Postgres view doesn't stay a star. The column list gets fixed when you create the view. Add a column to the table later and the view won't show it. Re-run CREATE OR REPLACE VIEW after the ALTER, or list the columns on purpose so nobody expects otherwise.
1
2
24
2026 had three Friday the 13ths. How many does 2027 have? Guess before you read the answer. SELECT d FROM generate_series('2027-01-13'::date, '2027-12-13', '1 month') d WHERE extract(isodow FROM d) = 5; Answer: just one, in August.
1
10
Tuesday 60-second challenge. Four values: 10, 20, 30, 40. What do percentile_cont(0.5) and percentile_disc(0.5) return in Postgres? Answer: 25 and 20. cont interpolates between the two middle values. disc returns the first real value at or past the halfway mark.
8
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;
1
9
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
10
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?
1
2
15
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