@@ -26,14 +26,99 @@ For example if we are looking for:
26
26
}
27
27
```
28
28
29
- the expresion is:
29
+ the expression is:
30
30
31
31
```
32
32
user.name = 'diego'
33
33
```
34
34
35
- Sevral expressions could be connected using ` AND ` & ` OR ` operators:
35
+ Sevral expressions could be connected using boolean ` AND ` & ` OR ` operators:
36
36
37
37
```
38
38
user.name = 'diego' AND site.url = 'diego.com'
39
39
```
40
+
41
+ Expression could be negated with ` NOT ` operator:
42
+
43
+ ```
44
+ NOT user.name = 'diego'
45
+ ```
46
+
47
+ JSON value could be one following types:
48
+
49
+ * array
50
+ * numeric
51
+ * object
52
+ * string
53
+ * boolean
54
+
55
+ You can check type using ` is ` operator:
56
+
57
+ ```
58
+ user.name is array
59
+ user.name is numeric
60
+ user.name is object
61
+ user.name is string
62
+ user.name is boolean
63
+ ```
64
+
65
+ For all types you ` = ` (equality) operator is defined:
66
+
67
+ ```
68
+ user.roles = ["admin","root"]
69
+ user.age = 3
70
+ user.active = true
71
+ user.address = {city: "SPb"}
72
+ user.name = "diego"
73
+ ```
74
+
75
+ For numerics there are expected comparison operators:
76
+
77
+ ```
78
+ x > 1 AND x < 10
79
+ x >= 1 AND x <= 10
80
+ ```
81
+
82
+ To check that scalar value belongs to some list:
83
+
84
+ ``` sql
85
+ select ' {a: 2}' ::jsonb @@ ' a IN (1,2,5)' ;
86
+ ```
87
+
88
+ For arrays there are convenient operators:
89
+
90
+ ``` sql
91
+ -- overlap
92
+ select ' {"a": {"b": [1,2,3]}}' ::jsonb @@ ' a.b && [1,2,5]' ;
93
+
94
+ -- contains
95
+ select ' {"a": {"b": [1,2,3]}}' ::jsonb @@ ' a.b @> [1,2]' ;
96
+
97
+ -- contained
98
+ select ' {"a": {"b": [1,2,3]}}' ::jsonb @@ ' a.b <@ [1,2,3,4,5]'
99
+ ```
100
+
101
+ If you just want to check that some path exists in json document use ` =* ` :
102
+
103
+ select '{"a": {"b": [ 1,2,3] }}'::jsonb @@ 'a.b = * '
104
+
105
+
106
+ Path expression supports wild cards:
107
+
108
+ ` # ` - any alement of array
109
+ ` % ` - any key in object
110
+ ` * ` - any path
111
+
112
+ ``` sql
113
+ select ' {a: {b: {c: 1}}}' ::jsonb @@ ' *.c = 1'
114
+ select ' {a: {b: {c: 1}}}' ::jsonb @@ ' a.%.c = 1'
115
+ select ' {a: {b: [1,2]}}' ::jsonb @@ ' a.b.# = 1'
116
+ ```
117
+
118
+ jsquery expression could be expressed recursively using ` () ` :
119
+
120
+ ```
121
+ address(city = "SPB" AND street = "Nevskiy")
122
+ ```
123
+
124
+ This means eval ` city = "SPB" AND street = "Nevskiy" ` expression in context of ` address ` attribute.
0 commit comments