From 682035e15f0c7ce8bfbf5fc29730740827f7be6c Mon Sep 17 00:00:00 2001 From: Prashant Pandey Date: Thu, 14 May 2026 14:14:26 +0530 Subject: [PATCH] Bind arrays correctly in PG updates --- .../postgres/FlatPostgresCollection.java | 4 +--- .../core/documentstore/postgres/Params.java | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/FlatPostgresCollection.java b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/FlatPostgresCollection.java index f78e663c3..3fb71934a 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/FlatPostgresCollection.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/FlatPostgresCollection.java @@ -1122,9 +1122,7 @@ private void executeUpdate( for (Object param : params) { ps.setObject(idx++, param); } - for (Object param : filterParams.getObjectParams().values()) { - ps.setObject(idx++, param); - } + filterParams.bindTo(connection, ps, idx); int rowsUpdated = ps.executeUpdate(); LOGGER.debug("Rows updated: {}", rowsUpdated); } catch (SQLException e) { diff --git a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/Params.java b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/Params.java index e5c2dc368..34caa65bc 100644 --- a/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/Params.java +++ b/document-store/src/main/java/org/hypertrace/core/documentstore/postgres/Params.java @@ -1,5 +1,9 @@ package org.hypertrace.core.documentstore.postgres; +import java.sql.Array; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import lombok.Getter; @@ -26,6 +30,21 @@ public Map getObjectParams() { return objectParams; } + public int bindTo(Connection connection, PreparedStatement ps, int startIndex) + throws SQLException { + int idx = startIndex; + for (Object value : objectParams.values()) { + if (value instanceof ArrayParam) { + ArrayParam arrayParam = (ArrayParam) value; + Array sqlArray = connection.createArrayOf(arrayParam.getSqlType(), arrayParam.getValues()); + ps.setArray(idx++, sqlArray); + } else { + ps.setObject(idx++, value); + } + } + return idx; + } + public static Builder newBuilder() { return new Builder(); }