while i know it is bad querying from JSON, but this is legacy data structure, so shit happen
\nhahaha
let say data on metadata is like this
\n{\n \"address1\": \"test\"\n}\nwhen i create query
\n-- name: FindByAddress :one\nSELECT * FROM \"user\" WHERE \"metadata\"->>'address1' = $1 LIMIT 1\nthe generated parameters will become like this
\ntype FindByAddressParams struct {\n\tmetadata json.RawMessage\n}\nSo, the question should it type on parameter become interface{} since just the owner of data who knows JSON value ?
The type of the address1 field on the JSON column isn't known at compile time. You're correct that the parameter type should be interface{} instead of json.RawMessage. I've created #743 to track that bug.
You probably know the type of address1, so you can always cast it to text:
\n-- name: FindByAddress :one\nSELECT * FROM authors WHERE \"metadata\"->>'address1' = $1::text LIMIT 1;\n-
|
i have table something like this on postgres while i know it is bad querying from JSON, but this is legacy data structure, so shit happen let say data on metadata is like this when i create query the generated parameters will become like this So, the question should it type on parameter become |
Beta Was this translation helpful? Give feedback.
-
|
The type of the address1 field on the JSON column isn't known at compile time. You're correct that the parameter type should be You probably know the type of address1, so you can always cast it to text: |
Beta Was this translation helpful? Give feedback.
-
|
why is it bad to query JSONB? |
Beta Was this translation helpful? Give feedback.
The type of the address1 field on the JSON column isn't known at compile time. You're correct that the parameter type should be
interface{}instead ofjson.RawMessage. I've created #743 to track that bug.You probably know the type of address1, so you can always cast it to text: