pgjdbc/pgjdbc GitHub issues and pull requests (mirror)  
help / color / mirror / Atom feed
From: sly461 (@sly461) <[email protected]>
To: pgjdbc/pgjdbc <[email protected]>
Subject: [pgjdbc/pgjdbc] issue #3743: Retrieving the result set from the multi-dimensional array will get an error in binary mode.
Date: Mon, 28 Jul 2025 13:30:03 +0000
Message-ID: <[email protected]> (raw)

Please read https://stackoverflow.com/help/minimal-reproducible-example 

**Describe the issue**
I'm trying to use a three-dimensional array. However, I found that I can retrieve the result set normally in regular mode, but an error occurs **in binary mode**.

**Driver Version?**
42.7.7

**Java Version?**
java 21

**OS Version?**
Windows 10

**PostgreSQL Version?**
PostgreSQL 14.18

**To Reproduce**
Steps to reproduce the behaviour:
```
import java.sql.*;
import java.util.Properties;

public class TestMultiDimensionalArrayRetrieveResultSets {
  public static void main(String []args) throws Exception {


    String url = "jdbc:postgresql://localhost:5432/test";

    Properties props = new Properties();
    props.setProperty("user", "test");
    props.setProperty("password", "test");
    // forceBinary
    props.setProperty("prepareThreshold", "-1");
    Connection conn = DriverManager.getConnection(url, props);
    Statement stmt = conn.createStatement();
    stmt.execute("DROP TABLE IF EXISTS TestArray");
    stmt.execute("CREATE TABLE TestArray(intarr int[])");
    stmt.execute("INSERT INTO TestArray VALUES ('{{{0},{1}},{{2},{3}},{{4},{5}}}')");
    ResultSet rs = stmt.executeQuery("SELECT intarr FROM TestArray");
    rs.next();

    // {{{0},{1}},{{2},{3}},{{4},{5}}}
    Array arr = rs.getArray(1);
    ResultSet arrrs = arr.getResultSet();
    arrrs.next();
    // {{0},{1}}
    Array arr1 =  arrrs.getArray(2);
    ResultSet arr1rs = arr1.getResultSet();
    arr1rs.next();
    // {0}
    Array arr11 =  arr1rs.getArray(2);
    ResultSet arr11rs = arr11.getResultSet();
    arr11rs.next();
    System.out.println(arr11rs.getInt(2));
    arr11rs.next();
    arr11rs.close();
    arr1rs.next();
    // {1}
    Array arr12 =  arr1rs.getArray(2);
    ResultSet arr12rs = arr12.getResultSet();
    arr12rs.next();
    System.out.println(arr12rs.getInt(2));
    arr12rs.next();
    arr12rs.close();
    arr1rs.next();
    arr1rs.close();
  }
}
```

**Expected behaviour**
I expected to be able to retrieve the values in a three-dimensional array, but it actually got an error **in binary mode**:
```
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: arraycopy: last source index 33554459 out of bounds for byte[84]
    at java.base/java.lang.System.arraycopy(Native Method)
    at org.postgresql.jdbc.PgArray.storeValues(PgArray.java:275)
    at org.postgresql.jdbc.PgArray.readBinaryResultSet(PgArray.java:205)
    at org.postgresql.jdbc.PgArray.getResultSetImpl(PgArray.java:374)
    at org.postgresql.jdbc.PgArray.getResultSet(PgArray.java:336)
    at org.postgresql.test.TestMultiDimensionalArrayRetrieveResultSets.main(TestMultiDimensionalArrayRetrieveResultSets.java:25)
```

view thread (5+ messages)  latest in thread

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: github://pgjdbc/pgjdbc
  Cc: [email protected], [email protected]
  Subject: Re: [pgjdbc/pgjdbc] issue #3743: Retrieving the result set from the multi-dimensional array will get an error in binary mode.
  In-Reply-To: <<[email protected]>>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox