IN () Means Nothing — JavaScript Bug Hunt
Inspired by the empty-list crash that has paged every team with a query builder: WHERE id IN () is a syntax error in real databases.
- Language: JavaScript
- Layer: Database
- Difficulty: Easy
- Concepts: SQL, Edge Cases
- Modelled on: Query builders
- Visible tests: a normal batch selects its rows; an empty batch matches nothing without crashing
- Reward: 50 XP for a complete fix
Briefing
Inspired by the empty-list crash that has paged every team with a query builder: WHERE id IN () is a syntax error in real databases. The empty case must compile to a query that matches nothing — deliberately.
The mock engine (locked) is as strict as Postgres.
Bug report
BUG-IN-EMPTY · Priority: High · Reported by: batch jobs
selectByIds(ids) -> { sql, params }:
- non-empty: "SELECT * FROM items WHERE id IN (?, ?, …)" with params
- empty: "SELECT * FROM items WHERE 1=0" (matches nothing, no params)
Observed: the nightly job passes an empty batch and the whole run dies on a SQL syntax error.
Logs
[job] SyntaxError: unexpected token ')' in: ... WHERE id IN ()The code as shipped
src/sql/selectByIds.js (editable)
// Builds the batched select.
exports.selectByIds = function (ids) {
var marks = ids.map(function () { return "?"; }).join(", ");
return { sql: "SELECT * FROM items WHERE id IN (" + marks + ")", params: ids };
};
Read-only context: src/sql/engine.js.
Open the hunt to edit the files, run the visible tests and submit against the hidden ones. More JavaScript bug hunts.