Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql: regression: invalid assignment cast: unknown -> int[] #71714

Closed
rafiss opened this issue Oct 19, 2021 · 2 comments
Closed

sql: regression: invalid assignment cast: unknown -> int[] #71714

rafiss opened this issue Oct 19, 2021 · 2 comments
Assignees
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) T-sql-queries SQL Queries Team

Comments

@rafiss
Copy link
Collaborator

rafiss commented Oct 19, 2021

Describe the problem

Previously, before assignment casts were added, the following PGJDBC test would pass.

https://github.com/pgjdbc/pgjdbc/blob/207ce36ec2c5cce30c454afa3e51f39bbe5bd26b/pgjdbc/src/test/java/org/postgresql/test/jdbc2/ArrayTest.java#L340

  @Test
  public void testSetNullArrays() throws SQLException {
    PreparedStatement pstmt = conn.prepareStatement("INSERT INTO arrtest VALUES (?,?,?)");

    final PGConnection arraySupport = conn.unwrap(PGConnection.class);

    pstmt.setArray(1, arraySupport.createArrayOf("int4", null));
    pstmt.setObject(2, conn.createArrayOf("float8", null));
    pstmt.setObject(3, arraySupport.createArrayOf("varchar", null));

    pstmt.executeUpdate();
    pstmt.close();

    Statement stmt = conn.createStatement();
    ResultSet rs = stmt.executeQuery("SELECT intarr, decarr, strarr FROM arrtest");
    Assert.assertTrue(rs.next());

    Array arr = rs.getArray(1);
    Assert.assertNull(arr);

    arr = rs.getArray(2);
    Assert.assertNull(arr);

    arr = rs.getArray(3);
    Assert.assertNull(arr);

    rs.close();
  }

Now it fails with

�[0;31;1mFAILURE�[0m   0.1sec, org.postgresql.test.jdbc2.�[0;1mArrayTest�[0m > �[0;1mtestSetNullArrays�[0m[binary = REGULAR]
    org.postgresql.util.PSQLException: ERROR: invalid assignment cast: unknown -> int[]
        at org.postgresql.core.v3.QueryExecutorImpl.receiveErrorResponse(QueryExecutorImpl.java:2553)
        at org.postgresql.core.v3.QueryExecutorImpl.processResults(QueryExecutorImpl.java:2285)
        at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:323)
        at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:481)
        at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:401)
        at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
        at org.postgresql.jdbc.PgPreparedStatement.executeUpdate(PgPreparedStatement.java:130)
        �[0;1mat org.postgresql.test.jdbc2.ArrayTest.testSetNullArrays(ArrayTest.java:349)

To Reproduce

Here's a repro that you can do from the CLI. This used to work with CRDB and still works with PG, but now it fails on master:

create table arrtest (intarr int8[]);
prepare q as INSERT INTO arrtest VALUES($1::int4[]);
execute q(null);

Now it results in

ERROR: invalid assignment cast: unknown -> int[]
SQLSTATE: 42846

Additional context
Causing #71564 to fail

cc @mgartner

@rafiss rafiss added the C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. label Oct 19, 2021
@blathers-crl blathers-crl bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label Oct 19, 2021
@blathers-crl blathers-crl bot added the T-sql-queries SQL Queries Team label Oct 19, 2021
@rafiss
Copy link
Collaborator Author

rafiss commented Oct 19, 2021

I added a simpler repro to the original issue

@rafiss
Copy link
Collaborator Author

rafiss commented Nov 30, 2021

Fixed by #72575

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Code not up to spec/doc, specs & docs deemed correct. Solution expected to change code/behavior. T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) T-sql-queries SQL Queries Team
Projects
Archived in project
Development

No branches or pull requests

2 participants