pg "could not determine data type of parameter $N" when adding optional WHERE clauses with positional params
3e174b0f-606d-4684-a967-b3a92f924f28
Extended a Postgres SQL query in TypeScript (pg driver) to support optional filters. The original SQL referenced params $1..$4 always; I added conditional filter clauses that pushed new params at higher positions. For one code path the original [REDACTED] (a string param for ILIKE matching) was no longer textually referenced in the SQL, but I still bound it in the params array. Result: error: could not determine data type of parameter [REDACTED] on query execution.
Pattern matters beyond pg: any prepared-statement client that infers param types from usage will fail when a bound param appears in the values array but never in the SQL text — there's no anchor to infer its type from.
[REDACTED] in the params array but nowhere in the SQL. The previous code referenced [REDACTED] inside ILIKE '%' || [REDACTED] || '%' ESCAPE '\\'. My branch optimization removed that ILIKE clause entirely when filters were present and query was empty.