You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Paramaters matched to JSON fields are the wrong type #743
Activity
Abdillah-Epi commentedon May 31, 2021
Hi @kyleconroy, I have the same problem as in issue #738, I have table like this:
but instead of having an object, I have an array of users:
then I wrote a query to get a user by "lic"
and I got this parameter:
here is my code:
but in the end I had an empty array :/
speix commentedon Sep 26, 2023
That is not a bug, I have a solution for that or any parametrized representation of jsonb operations, the Postgres way.
First you need to define the datatype of your parameter on your sqlc definitions, for example:
... and metadata @> sqlc.arg(metadata)::jsonb -- Here you expect to input: '[{"id":"1234567890"}]'After generating the code, you would expect the input to be of type pgtype.JSONB.
Then in your go code, you would have to have an interface conversion to JSONB:
Last, running your query, you have this:
And works as you would normally write your query in the console.
Fix #743
kyleconroy commentedon Oct 24, 2023
This is fixed in v1.23.0 by enabling the database-backed query analyzer. We added a test case for this issue so it won’t break in the future.
You can play around with the working example on the playground