Skip to content
Astera Technology

Why does a BINARY code column still match lowercase prefixes with LIKE?

Choose a case-sensitive pattern operator for the supplied ASCII prefix.

Download complete case notes and answer keys ↓

Prepare the report input

This original rule treats Ab and ab as different prefixes. SQLite LIKE normally folds ASCII case even though the column uses BINARY comparisons. For the fixed literal Ab prefix here, GLOB Ab* enforces case-sensitive matching.

Every record and report rule below is original and fictional. Reproduce the setup in a fresh SQLite test database; input previews include every table in this small fixture.

Synthetic input: codes
code
Ab1
Ax3
ab2
Download editable CSV ↓
Complete CREATE and INSERT fixture
CREATE TABLE codes(code TEXT COLLATE BINARY PRIMARY KEY); INSERT INTO codes VALUES('Ab1'),('ab2'),('Ax3');

Compare misleading and corrected results

Misleading SELECT: reproduce the defect
SELECT code FROM codes WHERE code LIKE 'Ab%' ORDER BY code;
Literal misleading result
code
Ab1
ab2
Download editable CSV ↓
Corrected SELECT
SELECT code FROM codes WHERE code GLOB 'Ab*' ORDER BY code;
Literal corrected result
code
Ab1
Download editable CSV ↓

LIKE retains Ab1 and ab2; GLOB retains Ab1. GLOB has its own wildcard syntax, so arbitrary prefixes need their own literal-escaping or substring policy.

Check a fresh boundary case

Adding uppercase AB4 does not add a match for the case-sensitive Ab prefix.

Recreate the original setup in another fresh database, then apply the change and corrected query below. For an empty result, the table displays a labelled empty-result marker rather than a data record.

Boundary change and corrected query
INSERT INTO codes VALUES('AB4');
SELECT code FROM codes WHERE code GLOB 'Ab*' ORDER BY code;
Literal boundary result
code
Ab1
Download editable CSV ↓

Should AB4 join the corrected result?

Show the worked answer

No. Its second character B differs from the required lowercase b. The result remains Ab1.

Related resources