Improve Handling of IN
Condition with JSON Data
#157
Replies: 1 comment
-
Hi @otaviojava The For a better explanation, let me use this syntax - see
With Oracle NoSQL, you can compare JSON atomics but you can also compare arrays and maps or combinations. You can do powerful queries. Without using the unbox operator, the following command will compare 2 arrays, the stored value in an array field
You could also want to do your IN against an array containing arrays [
Without using the unbox operator, you are in case (2)
By using the unbox operator, I can say that I want to compare against each element of the array - case (1) -
But If you try to compare a JSON atomic field with an array, you will have an error because you cannot compare a string value and an array, e.g
Note: maybe we can safely ignore this error because an array value ConclusionAgree, it is not standard SQL. Currently, we are promoting the flexibility of this approach for a NoSQL database vs years of standard SQL for relational databases. It allows us to work with JSON complex documents in a user-friendly way and improves the developer experience. But it seems that it complexifies 🤔 the understanding of basic queries like Currently, there is no implicit unboxing of arrays. Hope that my explanation helps you to understand why. You can read the documentation for the IN operator here for more details. We will discuss this internally. |
Beta Was this translation helpful? Give feedback.
-
I encountered an issue using the
IN
condition in SQL queries with JSON data in our database. The problem arises when the JSON field is compared to an array using theIN
operator. Currently, it requires explicit declaration of the array with[]
, and if not done correctly, it leads to a type mismatch error.Current Query:
Issue Description:
When using the
IN
condition in the provided query, it is required to declare the variable as an array using explicitly?[]
. Without this declaration, a type mismatch error occurs. This behavior differs from other NoSQL databases and Java drivers, where the system intelligently handles the array comparison without explicit declaration.Suggested Enhancement:
I suggest enhancing the database system to recognize when the value being compared against automatically is an array and handle it without the need for explicit declaration or conversion. It would improve the developer experience and align the behavior with industry standards and user expectations.
Expected Behavior:
Impact:
This enhancement would make working with JSON data in the database more user-friendly and improve the developer experience.
Beta Was this translation helpful? Give feedback.
All reactions