Skip to content

fix: quote string parameters in prepareQuery to prevent PostgreSQL type errors#10

Open
gakonst wants to merge 1 commit intowevm:mainfrom
gakonst:fix/parameter-quoting
Open

fix: quote string parameters in prepareQuery to prevent PostgreSQL type errors#10
gakonst wants to merge 1 commit intowevm:mainfrom
gakonst:fix/parameter-quoting

Conversation

@gakonst
Copy link

@gakonst gakonst commented Jan 15, 2026

Problem

String parameters like hex addresses (0xabc...) were being inserted into SQL queries without quotes via String(param), causing PostgreSQL to interpret them as bit literals instead of text values.

This resulted in bytea = bit type mismatch errors when queries had many OR conditions (e.g., >18 parameters).

Reproduction

// This fails with 'bytea = bit' error when hashList.length > ~18
const result = await QB.selectFrom('txs')
  .where('chain', '=', chainId)
  .where((eb) => eb.or(hashList.map((hash) => eb('hash', '=', hash))))
  .execute()

Root Cause

In prepareQuery(), line 373:

query = query.replaceAll(placeholder, String(param))

This converts 0xabc123... without SQL quoting, so PostgreSQL sees an unquoted 0x... which it interprets as a bit literal.

Solution

  1. Quote string parameters with single quotes and escape embedded quotes
  2. Sort replacements by placeholder length descending to ensure $10 is replaced before $1 (prevents partial replacements like $1 matching inside $10)

Testing

Verified fix resolves the issue in tempo-apps explorer with queries containing 20+ hash parameters.

@gakonst gakonst force-pushed the fix/parameter-quoting branch 3 times, most recently from 696b4bd to 82031c0 Compare January 15, 2026 02:09
Hex strings (0x...) should remain unquoted so sqlparser treats them as
HexStringLiteral, which the Index Supply backend converts to proper
PostgreSQL bytea format (\x...).

Other string parameters are quoted to be treated as text literals.

This fixes 'bytea = bit' type mismatch errors when querying with many
hex address/hash parameters.
@gakonst gakonst force-pushed the fix/parameter-quoting branch from 82031c0 to d5f4103 Compare January 15, 2026 02:12
gakonst added a commit to tempoxyz/tempo-apps that referenced this pull request Jan 15, 2026
Fixes explorer activity not showing due to 'bytea = bit' PostgreSQL
type mismatch when querying with hex strings in WHERE IN clauses.

See: wevm/idxs#10
gakonst added a commit to tempoxyz/tempo-apps that referenced this pull request Jan 15, 2026
Fixes explorer activity not showing due to 'bytea = bit' PostgreSQL
type mismatch when querying with hex strings in WHERE IN clauses.

See: wevm/idxs#10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant