Library/SQL that runs/SQL in the interview

Explain and fix AI-generated SQL

85 min5 partsCoreFundamentalsChecked Nov 2026
Start the lessonShort steps, each with something to do
What you'll learn
  • State the grain, what one output row means, before you read any SQL
  • Explain a query clause by clause in the order it runs, saying what one row is after each step
  • Build a fixture small enough to answer by hand, with a row aimed at each kind of bug
  • Catch a count of rows where the question counts people, a join that repeats rows, and a WHERE that turns a LEFT JOIN into an inner join
  • Handle NULLs in comparisons and sums, integer division and the ends of date ranges, in SQLite and PostgreSQL
  • Test generated SQL without an answer key, and know when to rewrite it instead of patching it
Part 1 of 5about 10 min
The method

Four generated queries that run and are wrong

One senior data scientist's report from an OpenAI loop describes this round: the interviewer hands over modular AI-generated SQL or Python and asks what its logic is and what's wrong with it (1 report). Another OpenAI data scientist report, from September 2026, lists 20 to 25 minutes of hands-on SQL in its live technical screen (1 report). Each is a single report, but 20 minutes isn't long, so the method has to be quick. Our version of the practice reads like this:

An assistant wrote four queries against users(user_id, signup_date, country) and events(user_id, event, event_date): daily active users, day-7 retention, conversion by country, and the users who never purchased. Each one runs and returns a tidy table. For each, tell me what it was meant to compute, what it actually computes, and fix it.

The practice comes in four levels, one query each. Level 1 is DAILY_ACTIVE_USERS, level 2 DAY7_RETENTION, level 3 CONVERSION_BY_COUNTRY, and level 4 NEVER_PURCHASED, where the events table holds a guest purchase with no user. Each has one bug that raises no error.

You don't fix them yet. The lesson builds a routine first: read the question back, read the query in the order it runs, and check it on a fixture you can answer by hand. Then it takes the bug classes one at a time: counts, joins, NULLs, integer division and dates. At the end you fix all four queries, level by level, in an interview simulation with a 40-minute timer.

This lesson builds on the SQL window functions lesson, which wrote queries from a blank file. Here the query is already written, and the skill is reading it.

The bugs fail on meaning, so run the same six steps every time

Generated SQL fails in one particular way, and the routine follows from it.

Predict

Generated SQL runs and returns a tidy table. Where do the bugs worth asking about fail?

Pick an answer above to see the rest

Write down what one output row means before you read any SQL

The routine's first step happens before you look at any SQL.

Predict

What do you write down before you read a line of the generated SQL?

Pick an answer above to see the rest

Read the clauses in the order they run, and say what one row is after each

The second step reads the query itself, but not from the top down.

Predict

Which runs first: SELECT, WHERE or FROM?

Pick an answer above to see the rest
Part 1 done
Part 2 of 5about 21 min
Fixtures and counts

A fixture is a handful of rows you can answer by hand

The third step is a fixture, and this lesson uses one throughout.

Predict

Why does the fixture give Ana two March orders?

Pick an answer above to see the rest

COUNT(*), COUNT(x) and COUNT(DISTINCT x) count three different things

The first bug class is the count itself.

Predict

Five orders, two with a promo. What's COUNT(promo)?

Pick an answer above to see the rest

Run the March query on the fixture, and check Austin by hand

Now run the March query from Part 1 on the fixture.

Predict

The March query counts COUNT(*) per city. In Austin, Ana ordered twice in March and Ben once. What does it report for Austin?

Pick an answer above to see the rest

Joining orders to item lines repeats each order once per line

A join can change what one row is too.

Predict

Join orders to their item lines, then SUM(o.total_cents). Order 10 has two item lines. What happens to its 2500?

Pick an answer above to see the rest

Count rows before and after a join to spot a fan-out without the answer

You can see a fan-out before you know the right answer.

Predict

Five orders join to six item lines. What does that row count tell you, with no answer key?

Pick an answer above to see the rest

Sum the item lines to one row per order before the join

The fix changes the many side's grain before the join.

Predict

A quick patch keeps the item join and writes SUM(DISTINCT o.total_cents). Austin's orders are 2500, 1800 and 1800. What revenue does Austin get?

Pick an answer above to see the rest
Part 2 done
Part 3 of 5about 27 min
NULLs and joins

A WHERE condition on the right-hand table can turn a LEFT JOIN into an inner join

The next class loses rows instead of repeating them.

Predict

Every customer with their March order count: a LEFT JOIN, with the date range in WHERE. What happens to Dee, who has no orders?

Pick an answer above to see the rest

Put the condition in ON, where it picks which orders match

The fix moves the condition into ON, next to the key. ON can hold more than the key. Here it attaches only the SPRING orders, and every customer stays:

SELECT c.name, COUNT(o.order_id) AS spring_orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.promo = 'SPRING'
GROUP BY c.customer_id, c.name
ORDER BY c.customer_id;
namespring_orders
Ana0
Ben1
Cy0
Dee0

Put the March range in ON the same way, and the March question comes out right:

namemarch_orders
Ana2
Ben1
Cy1
Dee0

The rows each version groups, side by side:

Range in WHERE: join every order, then cut
Ana, 10, 2026-03-02kept
Ana, 11, 2026-03-02kept
Ben, 12, 2026-03-15kept
Cy, 13, 2026-03-31kept
Cy, 14, 2026-04-01cut
Dee, NULLcut
3 customers left
Range in ON: attach only the March ordersCount
Ana, 10 and 112
Ben, 121
Cy, 131
Dee, NULL0
4 customers left

In ON, the condition decides which orders match. In WHERE, it decides which rows survive. This isn't a SQLite quirk. PostgreSQL's manual says the same: a condition in ON is applied before the join and one in WHERE after it, which doesn't matter for an inner join and matters a lot for an outer one.

In the editor, fix MARCH_ORDERS: every customer, with Dee's 0.

COUNT(*) counts the NULL row, and IS NULL on a right-hand key keeps only the rows with no match

Dee's 0 comes from COUNT(o.order_id), which skips her NULL row. Swap in COUNT(*) and it counts that row:

SELECT c.name, COUNT(*) AS march_orders
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at >= '2026-03-01'
                  AND o.placed_at < '2026-04-01'
GROUP BY c.customer_id, c.name
ORDER BY c.customer_id;
namemarch_orders
Ana2
Ben1
Cy1
Dee1

One right-hand condition belongs in WHERE on purpose. IS NULL on a right-hand key keeps only the rows that found no match. That's how you ask for customers with no March orders:

SELECT c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at >= '2026-03-01'
                  AND o.placed_at < '2026-04-01'
WHERE o.order_id IS NULL;
name
Dee

In the editor, fix APRIL_ORDERS: all three cities, with 0 where there were no April orders.

CheckpointKeep the cities with nothing

Asked for every city with its number of April orders, 0 for none, the assistant wrote APRIL_ORDERS. Only one city comes back. Fix it so all three do.

NULL means unknown, and WHERE keeps a row only when its condition is true

NULL is behind several of these bugs, so look at it alone first.

Predict

What does NULL = NULL give in SQL?

Pick an answer above to see the rest

WHERE promo <> 'SPRING' skips the orders whose promo is NULL

Not equal is the first place NULL bites.

Predict

WHERE promo <> 'SPRING' on the five orders. Which ones come back?

Pick an answer above to see the rest

One NULL in the list, and NOT IN is never true

The question: promo codes nobody has used. The queries below use four pieces of syntax:

  • VALUES ('FREESHIP'), ('SPRING'), ('WELCOME') is a table typed into the query, one code per row.
  • promos(code) names that table and its one column.
  • In a NOT EXISTS query, the subquery runs once for each outer row.
  • SELECT 1 is all that subquery needs to return, because only whether a row comes back matters.
WITH promos(code) AS (VALUES ('FREESHIP'), ('SPRING'), ('WELCOME'))
SELECT code
FROM promos
WHERE code NOT IN (SELECT promo FROM orders);

It returns no rows at all. NOT IN is true only when the code differs from every value in the list. Here's that check, written out for WELCOME, the code nobody used:

'WELCOME' NOT IN (SELECT promo FROM orders). The list is NULL, 'FREESHIP', 'SPRING', NULL, NULL:

ComparisonResult
'WELCOME' <> NULLNULL
'WELCOME' <> 'FREESHIP'true
'WELCOME' <> 'SPRING'true
'WELCOME' <> NULLNULL
'WELCOME' <> NULLNULL
all five togetherNULL, so WHERE drops WELCOME

One unknown is enough to make the whole check unknown. NOT EXISTS asks whether a matching row exists, and never compares anything with NULL. Here it finds the customers with no orders, running the subquery once for each customer c:

SELECT c.name
FROM customers c
WHERE NOT EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.customer_id);
name
Dee

In the editor, fix UNUSED_PROMOS with NOT EXISTS.

COUNT(x), SUM and AVG skip NULLs, and an empty SUM needs care

Aggregates are the third place NULL bites.

Predict

A city has no orders. What does SUM(total_cents) give for it after a LEFT JOIN?

Pick an answer above to see the rest
Part 3 done
Part 4 of 5about 15 min
Type traps

Two type traps: integer division and dates stored as text

In SQLite and PostgreSQL, an integer divided by an integer drops the fraction

The question: what share of orders used a promo?

SELECT COUNT(promo) / COUNT(*) AS promo_share
FROM orders;
promo_share
0

2 / 5 comes out as 0. In SQLite and PostgreSQL, an integer divided by an integer is an integer, cut toward zero. COUNT returns an integer in both, so every rate built from counts can hit this.

Put the 1.0 before the division, because multiplying after it is too late

Make one operand a real number before the division runs:

SELECT COUNT(promo) / COUNT(*) * 1.0 AS cast_after,
       1.0 * COUNT(promo) / COUNT(*) AS cast_before,
       CAST(COUNT(promo) AS REAL) / COUNT(*) AS cast_operand
FROM orders;
cast_aftercast_beforecast_operand
0.00.40.4

The first column is the trap. * and / have the same precedence and run left to right:

cast_aftercast_before
WrittenCOUNT(promo) / COUNT(*) * 1.01.0 * COUNT(promo) / COUNT(*)
First step2 / 5 * 1.01.0 * 2 / 5
Then0 * 1.02.0 / 5
Result0.00.4

On the left, the division runs first and loses the fraction. Multiplying by 1.0 afterwards only turns 0 into 0.0. In PostgreSQL, a ::numeric cast on either operand does the job of the 1.0.

Money in cents hits the same bug. The average order in dollars:

SELECT SUM(total_cents) / COUNT(*) / 100 AS avg_dollars_int,
       SUM(total_cents) / COUNT(*) / 100.0 AS avg_dollars
FROM orders;
avg_dollars_intavg_dollars
1919.4

AVG itself is safe here. SQLite's avg() returns a floating point value even when every input is an integer, and PostgreSQL's avg of an integer column returns numeric.

In the editor, fix PROMO_SHARE: each customer's share of orders with a promo, not just 0 or 1.

CheckpointA share that isn't 0 or 1

Asked for each customer's share of orders that used a promo, the assistant wrote PROMO_SHARE. Every share comes out exactly 0 or 1. Fix it.

BETWEEN with a bare end date loses times on the last day, so end before the next start

Dates in SQLite are text, as the SQL window functions lesson showed: SQLite has no date or time type of its own. Here placed_at is a TEXT column, so comparing two values compares strings. Strings in one consistent ISO format sort in time order, so that mostly works, until the last day of a range.

The question: orders placed in March.

SELECT order_id, placed_at
FROM orders
WHERE placed_at BETWEEN '2026-03-01' AND '2026-03-31';
order_idplaced_at
102026-03-02 12:15
112026-03-02 19:40
122026-03-15 08:05

Order 13, at 20:30 on March 31, is missing. Here's where values sort as strings, and which ones each range keeps. BETWEEN here is BETWEEN '2026-03-01' AND '2026-03-31', and half-open is >= '2026-03-01' AND < '2026-04-01'.

Value, in string orderBETWEENHalf-open
'2026-03-01'inin
'2026-03-02 12:15'inin
'2026-03-31'inin
'2026-03-31 00:00'outin
'2026-03-31 20:30'outin
'2026-04-01'outout
'2026-04-01 09:00'outout

'2026-03-31 20:30' starts with '2026-03-31' and keeps going, so it sorts after the upper bound. So does every March 31 value with a time, even midnight:

SELECT '2026-03-31 20:30' <= '2026-03-31' AS evening,
       '2026-03-31 00:00' <= '2026-03-31' AS midnight;
eveningmidnight
00

PostgreSQL has real timestamp types and nearly the same bug. Its docs say a date compared with a timestamp counts as midnight. So the range stops at 00:00 on March 31 and drops the rest of the day.

In either engine, use a half-open range: on or after the start, and strictly before the next start. Here it is for one day, March 2, where BETWEEN '2026-03-02' AND '2026-03-02' finds nothing at all:

SELECT order_id, placed_at
FROM orders
WHERE placed_at >= '2026-03-02' AND placed_at < '2026-03-03';
order_idplaced_at
102026-03-02 12:15
112026-03-02 19:40

The same shape works for a week or a month, and you never need to know how many days the month has.

In the editor, fix MARCH_IDS: the March orders, the late evening of the 31st included.

Subtracting two timestamps counts the hours, not the calendar days

Day counts have their own edge. Take two timestamps a calendar week apart.

Predict

julianday('2026-03-09 08:00') - julianday('2026-03-02 19:40'): about how many days is that?

Pick an answer above to see the rest

Each symptom points at a few bug classes

Run, compare, and name the class of each difference. One check usually tells the classes apart.

SymptomPoints atThe check
A count or sum too highcounting rows, not things; a join that repeats rowsrows before and after each join; COUNT(*) against distinct keys
One side's sums too high, the other side's righta fan-outgroup the joined rows by the one side's key, keep counts above 1
A row or group missingan inner join; a WHERE on a LEFT JOIN's right side; a NULL comparisonkeys on the left against rows in the output
No rows at allNOT IN over a NULL; a condition that's never truerun the subquery alone; count NULLs in the column
1 where 0 belongsCOUNT(*) over a LEFT JOIN's empty rowcount a right-hand key instead
NULL where 0 belongsSUM over no rowswrap the sum in COALESCE
A rate of exactly 0 or 1integer divisionlook at the numerator and denominator alone, then cast an operand
Off at the ends of a rangeBETWEEN on timestamps; an inclusive end; time zonesfixture rows late on the last day and just after it
Part 4 done
Part 5 of 5about 12 min
The worked example

A worked example

The question, read back and answered by hand

Here's one generated query, debugged from start to finish with the routine. The question:

For each city, March revenue in dollars and dishes sold. List every city, with zeros where there were no March orders.

Read it back. One row per city, so three rows: Austin, Boston, Denver. Revenue counts each March order once. Dishes add up item quantities. March runs from 2026-03-01 00:00 up to, not including, 2026-04-01.

Answer it by hand. Austin's March orders are 10, 11 and 12: 2500 + 1800 + 1800 = 6100 cents, and 1 + 2 + 3 + 1 = 7 dishes. Boston's only March order is 13, late on the 31st: 1500 cents and 1 dish. Order 14 is April. Denver has nothing.

cityrevenuedishes
Austin61.07
Boston15.01
Denver0.00

Read in run order, the generated query has three suspects before it runs

The generated query:

SELECT c.city,
       SUM(o.total_cents) / 100.0 AS revenue,
       SUM(i.qty) AS dishes
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
LEFT JOIN items i ON i.order_id = o.order_id
WHERE o.placed_at BETWEEN '2026-03-01' AND '2026-03-31'
GROUP BY c.city
ORDER BY c.city;

Explain it in run order. Say what one row is after each step:

RunsClauseOne row after it is
1FROM customers ca customer
1LEFT JOIN orders oan order, or a row of NULLs for a customer with none
1LEFT JOIN items ian item line, so order 10 and its 2500 appear twice
2WHERE placed_at BETWEEN '2026-03-01' AND '2026-03-31'a row in the range: the NULL rows can't pass, and the range ends at a bare date
3GROUP BY c.citya city
4SUM(o.total_cents) / 100.0a city, with each total summed once per item line

That's three suspects before you run anything: a fan-out, a WHERE that undoes the LEFT JOIN, and a boundary.

Predict

Run the generated query on the fixture. How many of the three cities come back?

Pick an answer above to see the rest

The rows under the GROUP BY show the extra 2500 and every row WHERE drops

Look at the rows the GROUP BY works on, before the WHERE gets to them. The last column is the WHERE's condition on each row:

SELECT c.city, c.name, o.order_id, o.placed_at, o.total_cents, i.qty,
       o.placed_at BETWEEN '2026-03-01' AND '2026-03-31' AS in_range
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
LEFT JOIN items i ON i.order_id = o.order_id
ORDER BY c.customer_id, o.order_id, i.dish;
citynameorder_idplaced_attotal_centsqtyin_range
AustinAna102026-03-02 12:15250011
AustinAna102026-03-02 12:15250021
AustinAna112026-03-02 19:40180031
AustinBen122026-03-15 08:05180011
BostonCy132026-03-31 20:30150010
BostonCy142026-04-01 09:00210020
DenverDeeNULLNULLNULLNULLNULL

Seven rows from four customers and five orders. Order 10's 2500 appears twice: that's the extra $25.00.

The WHERE keeps the four rows with a 1. It drops Cy's 20:30 order on the boundary, and Cy's April order, as it should. Dee's row gets NULL, so it goes too, and takes Denver with it.

Fix one thing at a time, and check that each fix moves only what it should

Fix 1, the rows that vanished. Move the date condition into the ON of the orders join, and delete the WHERE:

LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at BETWEEN '2026-03-01' AND '2026-03-31'

Fix 2, the boundary. Make the range half-open:

LEFT JOIN orders o ON o.customer_id = c.customer_id
                  AND o.placed_at >= '2026-03-01'
                  AND o.placed_at < '2026-04-01'

Fix 3, the fan-out. Bring items to one row per order in a CTE called dishes, join it in place of items, and sum d.dishes.

Fix 4, the blanks. The question asked for zeros, so wrap both sums in COALESCE.

Here's the output after each fix, each one run as a whole query on the fixture:

Each cell is revenue, then dishes:

AfterAustinBostonDenver
the generated query86.0, 7no rowno row
1: range moved into ON86.0, 7NULL, NULLNULL, NULL
2: half-open range86.0, 715.0, 1NULL, NULL
3: dishes CTE61.0, 715.0, 1NULL, NULL
4: COALESCE61.0, 715.0, 10.0, 0

Fix 1 brings every city back, but Boston is still blank: its one March order is outside the range. Fix 2 brings it in. Fix 3 takes the extra 2500 off Austin, and fix 4 turns Denver's blanks into zeros.

After fix 4 the output matches the hand answer, and each fix changed it only where you said it would.

Say it back. It was meant to report March revenue and dishes for every city. It reported revenue only for cities with a March order before the last day, and it counted each order's total once per item line. There were three causes. The item join repeated order totals. The date filter in WHERE threw away the rows the LEFT JOIN added. And BETWEEN with a bare end date cut off the last day. I moved the range into the ON clause as a half-open range, brought items to one row per order before the join, and turned empty sums into zeros.

In the editor, fix CITY_MARCH: the generated query, one fix at a time.

What interviewers ask next

Test generated SQL with six checks that need no answer key

How would you test generated SQL before trusting it? The fixture is the first answer. The second is a set of checks that need no answer key, so they work on production data the first time you run the query:

  • Rows across joins. Count before and after each join. A join to a lookup on its key keeps the count. A rise is a fan-out, a drop is an inner join or a filter.
  • The grain holds. In the output, COUNT(*) equals COUNT(DISTINCT key) for the key the question names.
  • Nothing is missing. The output has a row for every group in the base table, every city in customers.
  • Parts add up. Per-group totals sum to a total computed straight from the source table, with no joins.
  • Values are plausible. Rates sit between 0 and 1, and not all at one end. Counts don't exceed the population.
  • NULLs are counted. For every column you filter, join or compare on, you know how many NULLs it holds.

The parts-add-up check catches the worked example with no answer key:

SELECT SUM(total_cents) / 100.0 AS march_revenue
FROM orders
WHERE placed_at >= '2026-03-01' AND placed_at < '2026-04-01';
march_revenue
76.0

The generated query's cities added up to 86.0. That 86.0 holds two bugs pulling in opposite directions:

DollarsWhere it comes from
76.0March revenue, straight from orders
+25.0order 10's total, counted a second time by the fan-out
-15.0order 13, cut off by BETWEEN
86.0what the generated query's cities add up to

Here they don't cancel, so the total catches them. Two bugs can cancel exactly in a total, so a total is one check among several, never proof.

Comparing results is how OpenAI says it evaluates its own in-house data agent: "we compare both the SQL and the resulting data" (1 source). Reading the SQL tells you what to suspect. Only the data tells you what it returned.

Patch when one piece is wrong, and rewrite when the grain is wrong

Sometimes the right fix is a new query.

Predict

When should you rewrite generated SQL instead of patching it?

Pick an answer above to see the rest

These bugs all run, and each turns on a fact the question didn't spell out

Why do these bugs get past review? If you're asked which of these an assistant gets wrong most, don't invent a ranking you can't back up. Say what they share. Each one runs, returns numbers of the right shape, and turns on a fact the question didn't spell out: the grain, whether empty groups stay, what NULL means, the column types, where a range ends. Those are the facts to state when you prompt for SQL, and the ones to check when you review it.

The practice problem, start to finish

That's the routine and every bug class in the practice. The simulation hands you all four queries under a timer, so rehearse the order once.

Check yourself
5 questions
  1. 1.After joining orders to their item lines, a teammate patches the inflated numbers with COUNT(DISTINCT o.order_id) and SUM(DISTINCT o.total_cents). What's still wrong?

  2. 2.Every customer and their March order count, 0 for none. You move the date filter from WHERE into the LEFT JOIN's ON clause but keep COUNT(*). What does a customer with no orders get?

  3. 3.SELECT code FROM promos WHERE code NOT IN (SELECT promo FROM orders) returns nothing, though one code was never used. Why?

  4. 4.Two of five orders used a promo. In SQLite, what does SELECT COUNT(promo) / COUNT(*) * 1.0 FROM orders return?

  5. 5.placed_at holds text like '2026-03-31 20:30'. Which March orders does WHERE placed_at BETWEEN '2026-03-01' AND '2026-03-31' miss?

Where this shows up

The reports behind this lesson, each with its source.

Same L5 DS report, technical round: explain the logic of AI-generated SQL or Python and find what is wrong with it.

Candidate report·Aced, formerly Exponent (verified candidate report)Source

Same Sep 2026 DS report: the live technical screen included 20 to 25 minutes of hands-on SQL.

Candidate report·PracHub (first-person report, curated and edited by the site)·2026-09-28Source

OpenAI evaluates its data agent by comparing both the generated SQL and the resulting data, graded with OpenAI's Evals.

“we compare both the SQL and the resulting data, and feed these signals into OpenAI’s Evals grader.”
Company source·OpenAI engineering blog·2026-01-29Source

Practice

Sources (10)
  1. Built-in Aggregate Functions · SQLite documentation · Nov 13, 2025
    “The count(X) function returns a count of the number of times that X is not NULL in a group. The count(*) function (with no arguments) returns the total number of rows in the group.”
  2. SELECT · SQLite documentation · Oct 9, 2026
    “In an outer join, the extra NULL rows for non-matched rows on the other operand are added after ON clause processing but before WHERE clause processing.”
  3. NULL Handling in SQLite Versus Other Database Engines · SQLite documentation · Apr 18, 2022
    “The idea was to make SQLite work like all the other engines.”
  4. SQL Language Expressions · SQLite documentation · Aug 14, 2026
    “Integer divide yields an integer result, truncated toward zero.”
  5. Date And Time Functions · SQLite documentation · Jul 11, 2026
    “SQLite does not have a dedicated date/time datatype.”
  6. 7.2. Table Expressions · PostgreSQL 18 documentation · Sep 25, 2025
    “This is because a restriction placed in the ON clause is processed before the join, while a restriction placed in the WHERE clause is processed after the join. That does not matter with inner joins, but it matters a lot with outer joins.”
  7. 9.2. Comparison Functions and Operators · PostgreSQL 18 documentation · Sep 25, 2025
    “Ordinary comparison operators yield null (signifying “unknown”), not true or false, when either input is null.”
  8. 9.3. Mathematical Functions and Operators · PostgreSQL 18 documentation · Sep 25, 2025
    “Division (for integral types, division truncates the result towards zero)”
  9. 9.21. Aggregate Functions · PostgreSQL 18 documentation · Sep 25, 2025
    “In particular, sum of no rows returns null, not zero as one might expect”
  10. 9.9. Date/Time Functions and Operators · PostgreSQL 18 documentation · Sep 25, 2025
    “Similarly, a date value is assumed to represent midnight in the TimeZone zone when comparing it to a timestamp.”