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 f78e663c..3fb71934 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 e5c2dc36..34caa65b 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(); }