Skip to content

Commit 9279d1a

Browse files
committed
Example about schema validation in readme.
1 parent 6f99151 commit 9279d1a

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

README.md

+19
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)