You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -16,8 +16,6 @@ excerpt: "As modern multi-model databases increasingly support JSON, it's time t
16
16
17
17
As modern multi-model databases increasingly support JSON, it's time to explore what role [JSON schema](https://json-schema.org/) will play. In this post, we'll dive into the newly developed ["Database Vocabulary"](https://github.com/json-schema-org/vocab-database/blob/main/database.md), a proposed extension to the official JSON schema specification, developed by Oracle (with inputs from the MySQL and PostgreSQL teams). This vocabulary addresses key database tasks, including validation, type coercion/casting, and metadata preservation, making it easier to manage JSON in databases effectively and bridging the gap with existing relational data. Regardless of whether you are a JSON developer or a relational model developer, you'll learn something reading this post!
18
18
19
-

20
-
21
19
Oracle Database 23ai fully implements this new vocabulary, and we'll describe not only the concepts but we'll also see real-world examples of JSON schema validation in action and how to describe database objects in JSON schema.
22
20
23
21
## JSON Data Guide
@@ -568,7 +566,6 @@ BEGIN
568
566
'select getAnnotatedJSONSchema( ''PRODUCTS'' ) as schema');
569
567
570
568
COMMIT;
571
-
572
569
END;
573
570
/
574
571
```
@@ -596,13 +593,13 @@ With all this in place, our React frontend can now create the following form:
596
593
597
594

598
595
599
-
> Interestingly, whenever you change the schema annotation in the database, it is immediately reflected inside your browser once you refreshed it. You can try with:
600
-
> ```sql
601
-
>ALTER TABLE products MODIFY name ANNOTATIONS (
602
-
> REPLACE "title"'Product name'
603
-
>);
604
-
>```
605
-
>
596
+
<Infobox> Interestingly, whenever you change the schema annotation in the database, it is immediately reflected inside your browser once you refreshed it. You can try with:
597
+
```sql
598
+
ALTERTABLE products MODIFY name ANNOTATIONS (
599
+
REPLACE "title"'Product name'
600
+
);
601
+
```
602
+
</Infobox>
606
603
607
604
608
605
#### JSON Relational Duality View
@@ -723,7 +720,7 @@ Running the 2 queries above respectively returns the data in JSON format:
723
720
|Wooden spatula|4.99|42|
724
721
|Other nice product|5|10|
725
722
726
-
> The `_metadata` object will contain additional information such as an `etag` that can be used for [optimistic concurrency control](https://docs.oracle.com/en/database/oracle/oracle-database/23/jsnvu/using-optimistic-concurrency-control-duality-views.html).
723
+
<Infobox>The `_metadata` object will contain additional information such as an `etag` that can be used for [optimistic concurrency control](https://docs.oracle.com/en/database/oracle/oracle-database/23/jsnvu/using-optimistic-concurrency-control-duality-views.html).</Infobox>
727
724
728
725
#### POST method
729
726
@@ -745,9 +742,7 @@ BEGIN
745
742
end;');
746
743
747
744
COMMIT;
748
-
749
745
END;
750
-
751
746
/
752
747
```
753
748
@@ -757,7 +752,7 @@ With 23ai, a check constraint can now be marked as [`PRECHECK`](https://docs.ora
757
752
758
753
Once a check constraint is marked as `PRECHECK`, you have the choice whether or not to disable the check constraint on the table as the retrieved JSON schema with `dbms_json_schema.describe()` will contain the check constraints as well.
759
754
760
-
> We do **NOT** advise to disable check constraints as it would allow inserting bad data into the relational tables directly. The remark about `PRECHECK` constraints is here to provide as much information as possible.
755
+
<Danger>We do **NOT** advise to disable check constraints as it would allow inserting bad data into the relational tables directly. The remark about `PRECHECK` constraints is here to provide as much information as possible.</Danger>
761
756
762
757
```sql
763
758
-- Mark check constraints as PRECHECK
@@ -1018,7 +1013,7 @@ select p.content.publishedDate.timestamp() + interval '5' day
1018
1013
from posts p;
1019
1014
```
1020
1015
1021
-
> We use the item method `timestamp()` in the last statement above because otherwise the SQL dot notation would return a SQL `JSON` (by default in 23ai) on which we cannot apply an interval operation. However, because the value is already stored as `TIMESTAMP` inside the binary JSON format, there will be *no conversion* from `JSON` to `timestamp` here.
1016
+
<Infobox>We use the item method `timestamp()` in the last statement above because otherwise the SQL dot notation would return a SQL `JSON` (by default in 23ai) on which we cannot apply an interval operation. However, because the value is already stored as `TIMESTAMP` inside the binary JSON format, there will be *no conversion* from `JSON` to `timestamp` here.</Infobox>
1022
1017
1023
1018
Last but not least, by enabling type casting, native SQL data type checks are also performed ensuring 100% fidelity between stored binary values in the encoded JSON and SQL data types. As a result, we can store not just the standard JSON data types but also the SQL data types inside the encoded binary JSON such as `NUMBER`, `DATE`, `TIMESTAMP`, `TIMESTAMP WITH TIME ZONE`, `INTERVAL`, `RAW`, `VECTOR`, etc.
> The trigger executes asynchronously, hence not delaying DML response times, however, because of it being asynchronous, it may take a second before you will see the new virtual column.
1101
+
<Infobox>The trigger executes asynchronously, hence not delaying DML response times, however, because of it being asynchronous, it may take a second before you will see the new virtual column.</Infobox>
0 commit comments