Closed DavideD closed 1 month ago
It's not a bug: a plain string is a valid JSON value, as per rfc 7159.
What happens here is that a string value is stored in the jsonb column, regardless of its content.
If you want the content of the string to be converted to a JSON object, you must do it in the Java code with new JsonObject(string)
or in the SQL query
Thanks. I was surprised because it didn't seem to work when I tried, but it was just a typo I made.
@tsegismont On second thought, are we sure that this is not a bug?
It's true that I'm passing a parameter as String, but the SQL query is calling a function that should convert it to a proper JSON object. How come this is not happening? It seems like the cast( $1 as jsonb)
is ignored.
cast
is not ignored, it correctly converts a string to jsonb
. When the query is prepared, postgres doesn't know what kind of data it may expect, so when vert.x sends a string on the wire, it considers it as valid jsonb
content.
If you want a conversion of the content of the string, give Pg a hint with cast($1::text as jsonb)
For PostgreSQL and Vert.x SQL client 4.5.10
Given the following table:
The code:
will insert the row (using
psql
):instead of:
I'm not even sure how it's possible, because it's inserting a string in a
jsonb
column. I will try to create a test if necessary.