Postgresql JSON operators (->, ->>, @>) doesn't work in sqlx?


Does anyone know how to use the native Postgresql operators with sqlx?

Not sure, why but the Postgresql JSON operators don't seem to work in a query but works fine with psql.

sql::query_as( SELECT info -> 'customer' FROM table; );

Is this not supported or is there another syntax to achieve this?


Have you enabled the json feature flag for sqlx?

Yes I have it in my Cargo.toml.

sqlx = { version = “0.5.10”, features = [“runtime-tokio-rustls”, “postgres”, “uuid”, “time”, “any”, “json”]}

Found the problem. I was mapping to the wrong type. It’s working now.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.