Skip to content
Astera Technology

Why is stock released on its first unusable day?

Match the comparison operator to an explicit first-unusable-date policy.

Download complete case notes and answer keys ↓

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.

Synthetic input: batches
idqtyunusable_from
A32026-10-10
B52026-10-11
Download editable CSV ↓
Complete executable setup
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

Misleading query: use for diagnosis only
SELECT id,qty FROM batches WHERE unusable_from>='2026-10-10' AND qty>0 ORDER BY id;
Executed misleading result
idqty
A3
B5
Download editable CSV ↓
Corrected SQLite query
SELECT id,qty FROM batches WHERE unusable_from>'2026-10-10' AND qty>0 ORDER BY id;
Executed corrected result
idqty
B5
Download editable CSV ↓

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.

Boundary change in the fresh fixture
INSERT INTO batches VALUES ('C',0,'2026-10-12');
Executed boundary result from the corrected query
idqty
B5
Download editable CSV ↓

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.

Related resources