I have a table that has JSON data stored and I'm using json_exists
functions in the query. Below is my sample data from the column for one of the rows.
{"fields":["query.metrics.metric1.field1",
"query.metrics.metric1.field2",
"query.metrics.metric1.field3",
"query.metrics.metric2.field1",
"query.metrics.metric2.field2"]}
I want all those rows which have a particular field. So, I'm trying below.
SELECT COUNT(*)
FROM my_table
WHERE JSON_EXISTS(fields, '$.fields[*]."query.metrics.metric1.field1"');
It does not give me any results back. Not sure what I'm missing here. Please help.
Thanks
You can use
@
operator which refers to an occurrence of the arrayfields
such asDemo
Edit : The above case works for
12R2+
, considering that it doesn't work for your version(12R1
), try to useJSON_TABLE()
such asDemo