Skip to content

Commit 959271f

Browse files
committed
adding an example of JSON schema support to the multi model tutorial
1 parent f4e245a commit 959271f

2 files changed

Lines changed: 20 additions & 2 deletions

File tree

tutorials/hana-dbx-multi-model/hana-dbx-multi-model.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,25 @@ The following steps will demonstrate how to create a JSON collection that can be
212212

213213
Notice that the structure of the Guest Notes does not need to be defined in advance.
214214

215-
4. The JSON data can be returned as a JSON document, in a tabular result, or can be joined with data from a table.
215+
4. (Optional) You can use the [Support for JSON Schema](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-json-document-store-guide/support-for-json-schema) feature to define rules for your documents to adhere to. The example below restricts the "title" property to only accept strings.
216+
217+
```SQL
218+
CREATE COLLECTION "GUEST_NOTES_WITH_SCHEMA" JSON SCHEMA '{
219+
"$schema": "http://json-schema.org/draft-07/schema#",
220+
"properties": {
221+
"title": {
222+
"type": "string"
223+
}
224+
}
225+
}';
226+
227+
INSERT INTO "GUEST_NOTES_WITH_SCHEMA" VALUES ('{"title": 1, "FIRST_NAME": "Peter", "LAST_NAME": "Brown", "REQUEST": "requested an earl grey at 2:00"}'); -- throws error
228+
```
229+
230+
![Schema Validation Error](schema_validation_error.png)
231+
232+
233+
5. The JSON data can be returned as a JSON document, in a tabular result, or can be joined with data from a table.
216234

217235
```SQL
218236
SELECT * FROM GUEST_NOTES; --returns JSON
@@ -231,7 +249,7 @@ The following steps will demonstrate how to create a JSON collection that can be
231249

232250
For additional details see the [SELECT Statement](https://help.sap.com/docs/hana-cloud-database/sap-hana-cloud-sap-hana-database-json-document-store-guide/select-statement) in the JSON Document Store guide.
233251

234-
5. The properties of the JSON collection can also be viewed.
252+
6. The properties of the JSON collection can also be viewed.
235253

236254
![Collection properties](collection-properties.png)
237255

42.8 KB
Loading

0 commit comments

Comments
 (0)