Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 9279d1a

Browse filesBrowse files
committed
Example about schema validation in readme.
1 parent 6f99151 commit 9279d1a
Copy full SHA for 9279d1a

File tree

1 file changed

+19
-0
lines changed
Filter options

1 file changed

+19
-0
lines changed

‎README.md

Copy file name to clipboardExpand all lines: README.md
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,25 @@ examples.
187187

188188
Same rules apply when you search inside objects and branchy structures.
189189

190+
Type checking operators and "every" placeholders are useful for document
191+
schema validation. JsQuery matchig operator `@@` is immutable and can be used
192+
in CHECK constraint. See following example.
193+
194+
```sql
195+
CREATE TABLE js (
196+
id serial,
197+
data jsonb,
198+
CHECK (data @@ '
199+
name IS STRING AND
200+
similar_ids.#: IS NUMERIC AND
201+
points.#:(x IS NUMERIC AND y IS NUMERIC)'::jsquery));
202+
```
203+
204+
In this example check constraint validates that in "data" jsonb column:
205+
value of "name" key is string, value of "similar_ids" key is array of numerics,
206+
value of "points" key is array of objects which contain numeric values in
207+
"x" and "y" keys.
208+
190209
See our
191210
[pgconf.eu presentation](http://www.sai.msu.su/~megera/postgres/talks/pgconfeu-2014-jsquery.pdf)
192211
for more examples.

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.