Prepare the diagnostic input
The fixture names the field unusable_from: the batch cannot be released on or after that date. A >= comparison accidentally includes the boundary day. Define whether a source date means last usable or first unusable before choosing the operator; labels like expiry alone may be ambiguous.
Use a fresh SQLite test database for the complete setup below. Every record is fictional; quantities are units and input monetary columns ending in cents use integer currency cents. Calculated averages may include fractions of a cent. Input previews include every table in this small fixture.
| id | qty | unusable_from |
|---|---|---|
| A | 3 | 2026-10-10 |
| B | 5 | 2026-10-11 |
CREATE TABLE batches(id TEXT PRIMARY KEY,qty INTEGER,unusable_from TEXT);
INSERT INTO batches VALUES ('A',3,'2026-10-10'),('B',5,'2026-10-11');Reproduce the misleading result and correct it
SELECT id,qty FROM batches WHERE unusable_from>='2026-10-10' AND qty>0 ORDER BY id;| id | qty |
|---|---|
| A | 3 |
| B | 5 |
SELECT id,qty FROM batches WHERE unusable_from>'2026-10-10' AND qty>0 ORDER BY id;| id | qty |
|---|---|
| B | 5 |
At the 10 October cut-off, A is already unusable and B remains eligible by date and positive quantity. The wrong query includes A’s three units. The correction lists only B’s five; it does not certify product quality or shipping authorisation.
Check the boundary before applying the fix
Add a future-dated batch with zero units. It does not appear merely because its date is eligible; the positive-quantity requirement still applies.
For the boundary test, recreate the complete setup in another fresh synthetic database, apply only the change below, then rerun the corrected query. Do not apply a test mutation to a live system.
INSERT INTO batches VALUES ('C',0,'2026-10-12');| id | qty |
|---|---|
| B | 5 |
This is an invented date-only policy, not a legal shelf-life interpretation. Holds, recalls, storage conditions and time-of-day expiry require separate checks.
The displayed bad, corrected and boundary results were executed in SQLite and checked against separately authored expected rows. This demonstrates the stated fixture only; it does not test other database engines, production performance or your live schema.