Subject: [pgjdbc/pgjdbc] issue #3608: Support BigInteger[] in PgPreparedStatement#setObject(int, java.lang.Object)

From: "victornoel (@victornoel)" <[email-masked]>
Date: Thu, 17 Apr 2025 15:50:10 +0000

**Describe the issue**

Hi, I noticed that even though I can use `PreparedStatement.setObject` with an array of `BigInteger` I get the following exception:
```
Exception in thread "main" org.postgresql.util.PSQLException: Cannot cast an instance of [Ljava.math.BigInteger; to type Types.ARRAY
	at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1059)
	at default.Test.main(DefaultDomainContext.java:211)
Caused by: java.sql.SQLFeatureNotSupportedException
	at org.postgresql.jdbc.PgPreparedStatement.setObjectArray(PgPreparedStatement.java:777)
	at org.postgresql.jdbc.PgPreparedStatement.setObject(PgPreparedStatement.java:1056)
	... 1 more
```

If I do the same (see repro below) with `BigDecimal`, it works as expected.

**Driver Version?** 

42.7.5

**Java Version?**

21

**OS Version?**

Archlinux

**PostgreSQL Version?**

17

**To Reproduce**

```
    public static void main(String[] args) throws Exception {
        String url = "jdbc:postgresql://localhost:5432/postgres";
        Properties props = new Properties();
        props.setProperty("user", "postgres");
        props.setProperty("password", "postgres");
        try (Connection conn = DriverManager.getConnection(url, props)) {
            try (PreparedStatement statement = conn.prepareStatement("select ? = ANY(?)")) {
                statement.setObject(1, BigInteger.ONE);
                statement.setObject(2, new BigInteger[]{BigInteger.ONE});
                try (ResultSet rs = statement.executeQuery()) {
                    if (rs.next()) {
                        System.out.println("result: " + rs.getBoolean(1));
                    }
                }
            }
        }
    }
```

**Expected behaviour**

It would work :)

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Thu, 17 Apr 2025 16:12:12 +0000

The proper way to do this is use Connection.createArrayOf https://github.com/pgjdbc/pgjdbc/blob/1fb8dd1e06b19b4916b516ecf8aa3eda90bf2fcb/pgjdbc/src/main/java/org/postgresql/jdbc/PgConnection.java#L1495

---

From: "victornoel (@victornoel)" <[email-masked]>
Date: Thu, 17 Apr 2025 16:45:22 +0000

Hello @davecramer , I am indeed aware of that but I was wondering if we could get support for more of the typical Java types like it is already the case for String[], Long[] or as already mentioned BigDecimal[] in setObject().

I of course understand if this is too much out of the scope of the project.

---

From: "davecramer (@davecramer)" <[email-masked]>
Date: Thu, 17 Apr 2025 16:53:51 +0000

I have no issue with it if you want to provide a PR

---

From: "victornoel (@victornoel)" <[email-masked]>
Date: Fri, 18 Apr 2025 07:11:01 +0000

I started to look at it but it's not as easy to implement as `BigDecimal` because while there is `Oid.NUMERIC` that only matches `BigDecimal`, while for `BigInteger`, we would use `Oid.INT8` but it's already used for `long`/`Long`: so it's hard to reuse existing tests for example to introduce `BigIntegerObjectArraysTest`. I haven't even looked yet at the actual implementation ^^

Any advice here is welcome, but I will anyway try to continue by myself in the next weeks. Thanks!