Why Your AI's Status Filter Misses Rows With a Hidden Space
Asked for status = 'active' and some obviously active rows didn't show. The stored value is 'active ' — a trailing space. Equality does not trim. Forms, CSVs, and CHAR columns do this constantly.
You ask for status = 'active'. Half the active customers are missing. You open a row — it says active. The column is 'active '. Equality does not strip spaces. The admin UI usually does.
The value is not the label
WHERE status = 'active' -- misses 'active ', ' active', 'active\n'
WHERE TRIM(status) = 'active' -- catches those
CSV imports, form fields, and Excel "clean" columns do this constantly. CHAR(n) columns pad with spaces to a fixed width — 'active' in CHAR(10) is ten characters. Depending on the database, a comparison to 'active' may or may not pad the literal to match. Postgres character vs text is a common trap after a migration.
This sits next to case-sensitive search and empty string vs NULL. Those under-count too. The fix here is TRIM (or BTRIM), not ILIKE or IS NULL.
How to catch it
SELECT status, COUNT(*), LENGTH(status)
FROM customers
GROUP BY status
ORDER BY 2 DESC;
Two rows that look like active with lengths 6 and 7 is this bug. Wrapping the value in brackets — SELECT '[' || status || ']' — makes the space visible in chat.
The fix
WHERE TRIM(status) = 'active'
-- or normalize once
WHERE TRIM(BOTH FROM status) = 'active'
If you also have mixed case: LOWER(TRIM(status)) = 'active'. Don't stack functions until you've seen LENGTH — maybe it's only case, or only NULL.
The prompt that heads this off
When a text filter misses rows that look like they match, check
LENGTH and distinct values before changing the logic. TRIM both
the column and the literal if a CSV/import or CHAR column is involved.
Don't assume the UI's display is the stored bytes.
The short version
What you see in the admin UI is trimmed. What SQL compares is not. If a status filter is "obviously short," look at LENGTH before you rewrite the join.
Read-only MCP gateway: mcpserver.design.
Related reading: