This bug reports follows-up on quarkusio/quarkus#11501
The user initially reported they were not able to insert into jsonb column with Pg Client whereas the same query with Postgres JDBC works.
I proposed a better query to the user that works with both Postgres JDBC and the Pg Client as a workaround.
As for the issue, I did a little research and it seems the Pg client does not always send parameter types when preparing a query.
Consider the following table:
CREATE TABLE object_data (data JSONB)
And the following query:
INSERT INTO object_data (data) VALUES (to_json($1)) RETURNING (data)
If you execute:
PreparedQuery<RowSet<Row>> insertQuery = pgConnection.preparedQuery("INSERT INTO object_data (data) VALUES (to_json($1)) RETURNING (data)");
insertQuery.execute(Tuple.of("toto"), ctx.asyncAssertSuccess(rs -> {
Row row = rs.iterator().next();
Object value = row.getJson(0);
System.out.println("value = " + value);
}));
You will see:
io.vertx.pgclient.PgException: { "message": "could not determine polymorphic type because input has type unknown", "severity": "ERROR", "code": "42804", "file": "parse_coerce.c", "line": "1866", "routine": "enforce_generic_type_consistency" }
But if you change this:
|
PrepareStatementCommand prepareCmd = prepareCommand(queryCmd, cache, false); |
to
PrepareStatementCommand prepareCmd = prepareCommand(queryCmd, cache, true);
Then you get the expected result:
My understanding is that we do not want to send the parameters because we wouldn't be able to cache the prepared statement, correct?
I believe Posgres JDBC checks if the types are the same before reusing a cached statement and, if they are not the same, prepares the statement again with new types.
This bug reports follows-up on quarkusio/quarkus#11501
The user initially reported they were not able to insert into jsonb column with Pg Client whereas the same query with Postgres JDBC works.
I proposed a better query to the user that works with both Postgres JDBC and the Pg Client as a workaround.
As for the issue, I did a little research and it seems the Pg client does not always send parameter types when preparing a query.
Consider the following table:
And the following query:
If you execute:
You will see:
But if you change this:
vertx-sql-client/vertx-sql-client/src/main/java/io/vertx/sqlclient/impl/SocketConnectionBase.java
Line 194 in a08a7d7
to
Then you get the expected result:
My understanding is that we do not want to send the parameters because we wouldn't be able to cache the prepared statement, correct?
I believe Posgres JDBC checks if the types are the same before reusing a cached statement and, if they are not the same, prepares the statement again with new types.