Two SQL Traps That Run Without Error and Return Wrong Results
Implicit type conversion and NULL propagation are universal SQL behaviors, not KES-specific quirks. A batch reconciliation script that silently merges orders or drops customers can produce financial errors that survive several processing stages before anyone notices.
Comparing a varchar column to an unquoted integer causes the database to cast every stored value to an integer before comparison. Strings like '00123', '123', and '0123' all become 123, so a query meant for one order returns three. The syntax is legal and no error fires, making the data corruption invisible to logs and monitoring. On large tables the cast also disables the B-tree index on that column, forcing a full scan.
A NOT IN subquery that contains even one NULL poisons the entire outer query. The expression expands to a chain of ANDed inequalities, and any comparison with NULL evaluates to unknown. Because WHERE discards both false and unknown, every row gets filtered out. NOT EXISTS is immune because it checks only for the existence of a matching row, and a NULL value matches nothing.
The common thread is that both bugs pass clean test suites and only surface against real data with small imperfections: leading zeros, a missing foreign key. The fix is to match the literal type to the column type and to default to NOT EXISTS for anti-join queries unless the column has a NOT NULL constraint.
Implicit type conversion is a silent data-corruption mechanism: it produces no error, no warning, and no log entry, yet it can merge distinct business entities into one.
The NOT IN trap is a direct consequence of SQL's three-valued logic, but most developers treat NULL behavior as an edge case rather than a default failure mode for an entire query class.
Clean test data is the common enabler for both bugs. The real safeguard is testing with deliberately dirty data—leading zeros, null foreign keys—before the query reaches production.