I know that to retrieve all records where context.scid equals 13, I would use the query:
SELECT * FROM table WHERE context.scid = ‘13’;
However, I need to perform a search to find records where the number 13 appears anywhere within the context field, regardless of the key. Could you please advise on the best approach to accomplish this?
I am uncertain whether the ‘IN’ operator functions within a JSON context.
I’m afraid it doesn’t:
mysql> drop table if exists t; create table t(j json); insert into t values(1, '{"a": 1}'); select any(bigint(x)=1 for x in j) from t;
--------------
drop table if exists t
--------------
Query OK, 0 rows affected (0.01 sec)
--------------
create table t(j json)
--------------
Query OK, 0 rows affected (0.00 sec)
--------------
insert into t values(1, '{"a": 1}')
--------------
Query OK, 1 row affected (0.00 sec)
--------------
select any(bigint(x)=1 for x in j) from t
--------------
+-----------------------------+
| any(bigint(x)=1 for x in j) |
+-----------------------------+
| 0 |
+-----------------------------+
1 row in set (0.00 sec)
--- 1 out of 1 results in 0ms ---
I have a specific query regarding data retrieval from manticore database. Currently, I use the following SQL query to fetch records:
SELECT * FROM table WHERE context.scid = 13;
I am exploring the possibility of specifying the value (in this case, 13) without explicitly stating the key (context.scid), similar to how it’s done in Elasticsearch.
Query String Query: Allows you to search for a value across all fields or within a specific object without needing to explicitly state the key for each search.
Match Query: Requires specifying the field but is useful for structured and more precise searches.
These Elasticsearch examples showcase how flexible queries can be structured without needing to specify each key explicitly, providing a way to search across multiple fields or specific objects more efficiently.