I have a column type of jsonb named changes
THis is the structure of my column.
[["change","is_enabled",[false,true]]]
I want to query within the column.
I want to find all the rows that "is_enabled" = true
I have tried everything. Can you please help me find a solution
Best Answer
This is a terrible schema. You're essentially storing an array of arrays. And what you're asking is how to query a jsonb-array, for any elements that are themselves an array that happen to have an array after a string named "is_enabled" which inside the array, has an element of
true
.That's going to be extremely ugly. Nothing about this makes sense. Your JSON schema should just have one object that has
{"is_enabled":true}
, or something like this{"name":"change","is_enable":true}
. As is, you need something very ugly,You can unnest both JSON array's getting to the inside with relative ease. Then you'll have to mark the row after the
is_enabled
element in the array,From this, it's simple using
bool_or
, and another selectWe can add more rows to the
VALUES
expression to test itIf you just want the ones where
bool_or IS TRUE
useHAVING
..