Skip to content

Bind arrays correctly in PG updates#307

Merged
suddendust merged 2 commits into
mainfrom
pg_bind_arrays_correctly
May 14, 2026
Merged

Bind arrays correctly in PG updates#307
suddendust merged 2 commits into
mainfrom
pg_bind_arrays_correctly

Conversation

@suddendust
Copy link
Copy Markdown
Contributor

@suddendust suddendust commented May 14, 2026

Fix: ArrayParam support in UPDATE execution path

Problem

PR #258 added = ANY(?) optimization for SELECT queries, replacing IN ($1, $2, ..., $N) with a single array parameter. However, the UPDATE path in FlatPostgresCollection.executeUpdate() bound WHERE clause params with a raw setObject() loop, which doesn't know how to handle the Params.ArrayParam wrapper:

PSQLException: Can't infer the SQL type to use for an instance of
org.hypertrace.core.documentstore.postgres.Params$ArrayParam.
SQLState: 07006

Affected query pattern:

UPDATE "entities_api_shadow"
  SET "attributes.labels" = ?, "lastUpdateTime" = ?
  WHERE "key" = ANY(?)
                  ^^^^ ArrayParam not unwrapped

The SELECT path already handled this correctly via PostgresUtils.enrichPreparedStatementWithParams(), but the UPDATE path was a separate code path that bypassed it.

Fix

Params.java — Added bindTo(Connection, PreparedStatement, int startIndex) method that encapsulates ArrayParamcreateArrayOfsetArray dispatch. Returns the next unused index for chaining.

FlatPostgresCollection.java — Replaced the raw setObject() loop for filter params with a single call:

// Before
for (Object param : filterParams.getObjectParams().values()) {
    ps.setObject(idx++, param);  // breaks on ArrayParam
}

// After
filterParams.bindTo(connection, ps, idx);

This is already being done here:

@codecov
Copy link
Copy Markdown

codecov Bot commented May 14, 2026

Codecov Report

❌ Patch coverage is 54.54545% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 81.68%. Comparing base (3bcae6c) to head (89fec55).

Files with missing lines Patch % Lines
...hypertrace/core/documentstore/postgres/Params.java 50.00% 4 Missing and 1 partial ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##               main     #307      +/-   ##
============================================
- Coverage     81.73%   81.68%   -0.05%     
  Complexity     1532     1532              
============================================
  Files           241      241              
  Lines          7412     7420       +8     
  Branches        717      718       +1     
============================================
+ Hits           6058     6061       +3     
- Misses          908      912       +4     
- Partials        446      447       +1     
Flag Coverage Δ
integration 81.68% <54.54%> (-0.05%) ⬇️
unit 55.72% <0.00%> (-0.07%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@github-actions
Copy link
Copy Markdown

Test Results

  122 files  ±0    122 suites  ±0   37s ⏱️ +2s
  829 tests ±0    828 ✅ ±0  1 💤 ±0  0 ❌ ±0 
1 166 runs  ±0  1 165 ✅ ±0  1 💤 ±0  0 ❌ ±0 

Results for commit 89fec55. ± Comparison against base commit 3bcae6c.

@suddendust suddendust merged commit 059875b into main May 14, 2026
5 of 7 checks passed
@suddendust suddendust deleted the pg_bind_arrays_correctly branch May 14, 2026 10:01
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.

2 participants