How to compare JSON integer values #1708
-
Environment
Description of issueIf I have a JSON field in an exposed Postgrest view, for example containing
I seem to be able to retrieve entries as text using the standard PostgreSQL JSON '->>' operator. The following both work
But I cannot retrieve properly using integer comparison even if casting values to integer. Both the following examples erroneously match the entry above because '88' is lexographically less than '9'
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 5 replies
-
Instead of the double arrowhead operator GET /example?json_field->b_int=lt.9 More info about pg json operators at: https://www.postgresql.org/docs/current/functions-json.html Edit: Note that comparison operators will only work if the type is |
Beta Was this translation helpful? Give feedback.
Instead of the double arrowhead operator
->>
(get as text) use the single arrowhead operator->
(get as json). Like:More info about pg json operators at: https://www.postgresql.org/docs/current/functions-json.html
Edit: Note that comparison operators will only work if the type is
jsonb
and notjson