pgjdbc-ng icon indicating copy to clipboard operation
pgjdbc-ng copied to clipboard

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

Open kirillsalykin opened this issue 4 years ago • 0 comments

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
);

kirillsalykin avatar Aug 30 '21 11:08 kirillsalykin