impossibl / pgjdbc-ng

A new JDBC driver for PostgreSQL aimed at supporting the advanced features of JDBC and Postgres
https://impossibl.github.io/pgjdbc-ng
Other
596 stars 108 forks source link

TEXT and VARCHAR types seems to be not compatible from `writeString` pov (used from UDT java.sql.SQLData) #558

Open kirillsalykin opened 2 years ago

kirillsalykin commented 2 years ago

There seems to be incompability between VARCHAR and TEXT (at least for custom composite type). when one uses writeString into field which declared as TEXT exception is thrown:

   error: com.impossibl.postgres.jdbc.PGSQLSimpleException: wrong data type: 1043, expected 25
           ErrorUtils.java:  197  com.impossibl.postgres.jdbc.ErrorUtils/makeSQLException
           ErrorUtils.java:  174  com.impossibl.postgres.jdbc.ErrorUtils/makeSQLException
           ErrorUtils.java:  161  com.impossibl.postgres.jdbc.ErrorUtils/makeSQLException
   PGDirectConnection.java:  514  com.impossibl.postgres.jdbc.PGDirectConnection/execute
   PGDirectConnection.java:  522  com.impossibl.postgres.jdbc.PGDirectConnection/executeTimed
        PreparedQuery.java:  121  com.impossibl.postgres.jdbc.PreparedQuery/executeStatement
        PreparedQuery.java:  194  com.impossibl.postgres.jdbc.PreparedQuery/execute
          PGStatement.java:  378  com.impossibl.postgres.jdbc.PGStatement/executeStatement
  PGPreparedStatement.java:  339  com.impossibl.postgres.jdbc.PGPreparedStatement/execute
  PGPreparedStatement.java:  373  com.impossibl.postgres.jdbc.PGPreparedStatement/executeLargeUpdate
  PGPreparedStatement.java:  367  com.impossibl.postgres.jdbc.PGPreparedStatement/executeUpdate
ProxyPreparedStatement.java:   61  com.zaxxer.hikari.pool.ProxyPreparedStatement/executeUpdate
HikariProxyPreparedStatement.java:   -1  com.zaxxer.hikari.pool.HikariProxyPreparedStatement/executeUpdate

But everything works fine if VARCHAR is used.

SQL taken from https://www.postgresql.org/docs/current/rowtypes.html

CREATE TYPE inventory_item AS (
    name            text, -- replace it with varchar and everything is good
    supplier_id     integer,
    price           numeric
);

CREATE TABLE on_hand (
    item      inventory_item,
    count     integer
);