Reputation: 17
Here is a little snippet of my json text which is in a column in a database. I want to write a query that will return a Boolean value if the values for "1", "2", etc. = 0. So if "1": 0 I want to have a false value so then I can write a conditional statement to display a message depending of the Boolean value.
{
"ENABLE": [
{
"1": 1,
"2": 1,
"3": 1,
"4": 1
}
]
}
Upvotes: 0
Views: 100
Reputation: 24593
here is one way using jsonb
functions:
select jsonb_array_elements((jsonb_extract_path(jsoncolumn::jsonb,'ENABLE'))) @> '{"4":1}'::jsonb as checking
from test
'{"4":1}' can be parameterized, as if you make a procedure , or if you build your query as dynamic sql.
db<>fiddle here
Upvotes: 1