-
Notifications
You must be signed in to change notification settings - Fork 49
/
jsquery--1.1.sql
304 lines (256 loc) · 7.83 KB
/
jsquery--1.1.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
-- complain if script is sourced in psql, rather than via CREATE EXTENSION
\echo Use "CREATE EXTENSION jsquery" to load this file. \quit
CREATE TYPE jsquery;
CREATE FUNCTION jsquery_in(cstring)
RETURNS jsquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_out(jsquery)
RETURNS cstring
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE TYPE jsquery (
INTERNALLENGTH = -1,
INPUT = jsquery_in,
OUTPUT = jsquery_out,
STORAGE = extended
);
CREATE FUNCTION jsquery_json_exec(jsquery, jsonb)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION json_jsquery_exec(jsonb, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR @@ (
LEFTARG = jsquery,
RIGHTARG = jsonb,
PROCEDURE = jsquery_json_exec,
COMMUTATOR = '@@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE OPERATOR @@ (
LEFTARG = jsonb,
RIGHTARG = jsquery,
PROCEDURE = json_jsquery_exec,
COMMUTATOR = '@@',
RESTRICT = contsel,
JOIN = contjoinsel
);
CREATE FUNCTION json_jsquery_filter(jsonb, jsquery)
RETURNS jsonb
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR ~~ (
LEFTARG = jsonb,
RIGHTARG = jsquery,
PROCEDURE = json_jsquery_filter
);
CREATE FUNCTION jsquery_join_and(jsquery, jsquery)
RETURNS jsquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR & (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_join_and,
COMMUTATOR = '&'
);
CREATE FUNCTION jsquery_join_or(jsquery, jsquery)
RETURNS jsquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR | (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_join_or,
COMMUTATOR = '|'
);
CREATE FUNCTION jsquery_not(jsquery)
RETURNS jsquery
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR ! (
RIGHTARG = jsquery,
PROCEDURE = jsquery_not
);
CREATE FUNCTION jsquery_lt(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_le(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_eq(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_ne(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_ge(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE FUNCTION jsquery_gt(jsquery, jsquery)
RETURNS bool
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR < (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_lt,
COMMUTATOR = '>',
NEGATOR = '>=',
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel
);
CREATE OPERATOR <= (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_le,
COMMUTATOR = '>=',
NEGATOR = '>',
RESTRICT = scalarltsel,
JOIN = scalarltjoinsel
);
CREATE OPERATOR = (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_eq,
COMMUTATOR = '=',
NEGATOR = '<>',
RESTRICT = eqsel,
JOIN = eqjoinsel,
HASHES,
MERGES
);
CREATE OPERATOR <> (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_ne,
COMMUTATOR = '<>',
NEGATOR = '=',
RESTRICT = neqsel,
JOIN = neqjoinsel
);
CREATE OPERATOR >= (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_ge,
COMMUTATOR = '<=',
NEGATOR = '<',
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel
);
CREATE OPERATOR > (
LEFTARG = jsquery,
RIGHTARG = jsquery,
PROCEDURE = jsquery_gt,
COMMUTATOR = '<',
NEGATOR = '<=',
RESTRICT = scalargtsel,
JOIN = scalargtjoinsel
);
CREATE FUNCTION jsquery_cmp(jsquery, jsquery)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR CLASS jsquery_ops
DEFAULT FOR TYPE jsquery USING btree AS
OPERATOR 1 < ,
OPERATOR 2 <= ,
OPERATOR 3 = ,
OPERATOR 4 >= ,
OPERATOR 5 >,
FUNCTION 1 jsquery_cmp(jsquery, jsquery);
CREATE FUNCTION jsquery_hash(jsquery)
RETURNS int4
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR CLASS jsquery_ops
DEFAULT FOR TYPE jsquery USING hash AS
OPERATOR 1 =,
FUNCTION 1 jsquery_hash(jsquery);
CREATE OR REPLACE FUNCTION gin_compare_jsonb_value_path(bytea, bytea)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_compare_partial_jsonb_value_path(bytea, bytea, smallint, internal)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_jsonb_value_path(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_jsonb_query_value_path(anyarray, internal, smallint, internal, internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_consistent_jsonb_value_path(internal, smallint, anyarray, integer, internal, internal, internal, internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_triconsistent_jsonb_value_path(internal, smallint, anyarray, integer, internal, internal, internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR CLASS jsonb_value_path_ops
FOR TYPE jsonb USING gin AS
OPERATOR 7 @>,
OPERATOR 14 @@ (jsonb, jsquery),
FUNCTION 1 gin_compare_jsonb_value_path(bytea, bytea),
FUNCTION 2 gin_extract_jsonb_value_path(internal, internal, internal),
FUNCTION 3 gin_extract_jsonb_query_value_path(anyarray, internal, smallint, internal, internal, internal, internal),
FUNCTION 4 gin_consistent_jsonb_value_path(internal, smallint, anyarray, integer, internal, internal, internal, internal),
FUNCTION 5 gin_compare_partial_jsonb_value_path(bytea, bytea, smallint, internal),
FUNCTION 6 gin_triconsistent_jsonb_value_path(internal, smallint, anyarray, integer, internal, internal, internal),
STORAGE bytea;
CREATE OR REPLACE FUNCTION gin_compare_jsonb_path_value(bytea, bytea)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_compare_partial_jsonb_path_value(bytea, bytea, smallint, internal)
RETURNS integer
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_jsonb_path_value(internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_extract_jsonb_query_path_value(anyarray, internal, smallint, internal, internal, internal, internal)
RETURNS internal
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_consistent_jsonb_path_value(internal, smallint, anyarray, integer, internal, internal, internal, internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_triconsistent_jsonb_path_value(internal, smallint, anyarray, integer, internal, internal, internal)
RETURNS boolean
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OPERATOR CLASS jsonb_path_value_ops
FOR TYPE jsonb USING gin AS
OPERATOR 7 @>,
OPERATOR 14 @@ (jsonb, jsquery),
FUNCTION 1 gin_compare_jsonb_path_value(bytea, bytea),
FUNCTION 2 gin_extract_jsonb_path_value(internal, internal, internal),
FUNCTION 3 gin_extract_jsonb_query_path_value(anyarray, internal, smallint, internal, internal, internal, internal),
FUNCTION 4 gin_consistent_jsonb_path_value(internal, smallint, anyarray, integer, internal, internal, internal, internal),
FUNCTION 5 gin_compare_partial_jsonb_path_value(bytea, bytea, smallint, internal),
FUNCTION 6 gin_triconsistent_jsonb_path_value(internal, smallint, anyarray, integer, internal, internal, internal),
STORAGE bytea;
CREATE OR REPLACE FUNCTION gin_debug_query_value_path(jsquery)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;
CREATE OR REPLACE FUNCTION gin_debug_query_path_value(jsquery)
RETURNS text
AS 'MODULE_PATHNAME'
LANGUAGE C STRICT IMMUTABLE;