PostgreSQL Source Code: src/backend/utils/adt/jsonbsubs.c Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
16
24
25
26
28{
29 bool expectArray;
31
34
35
36
37
38
39
40
41
42static void
44 List *indirection,
46 bool isSlice,
47 bool isAssignment)
48{
51
52
53
54
55
56 foreach(idx, indirection)
57 {
59 Node *subExpr;
60
61 if (isSlice)
62 {
64
66 (errcode(ERRCODE_DATATYPE_MISMATCH),
67 errmsg("jsonb subscript does not support slices"),
69 }
70
72 {
74 targetType = UNKNOWNOID;
75
77 subExprType = exprType(subExpr);
78
79 if (subExprType != UNKNOWNOID)
80 {
81 Oid targets[2] = {INT4OID, TEXTOID};
82
83
84
85
86
87
88
89 for (int i = 0; i < 2; i++)
90 {
92 {
93
94
95
96
97 if (targetType != UNKNOWNOID)
99 (errcode(ERRCODE_DATATYPE_MISMATCH),
101 errhint("jsonb subscript must be coercible to only one type, integer or text."),
103
104 targetType = targets[i];
105 }
106 }
107
108
109
110
111 if (targetType == UNKNOWNOID)
113 (errcode(ERRCODE_DATATYPE_MISMATCH),
115 errhint("jsonb subscript must be coercible to either integer or text."),
117 }
118 else
119 targetType = TEXTOID;
120
121
122
123
124
125
126
128 subExpr, subExprType,
129 targetType, -1,
132 -1);
133 if (subExpr == NULL)
135 (errcode(ERRCODE_DATATYPE_MISMATCH),
136 errmsg("jsonb subscript must have text type"),
138 }
139 else
140 {
141
142
143
144
147 (errcode(ERRCODE_DATATYPE_MISMATCH),
148 errmsg("jsonb subscript does not support slices"),
150 }
151
152 upperIndexpr = lappend(upperIndexpr, subExpr);
153 }
154
155
158
159
160 sbsref->refrestype = JSONBOID;
161 sbsref->reftypmod = -1;
162}
163
164
165
166
167
168
169
170
171
172
173
174static bool
178{
181
182
183
184
185
186
187
188
192
193
194 for (int i = 0; i < sbsrefstate->numupper; i++)
195 {
197 {
198
200 {
203 (errcode(ERRCODE_NULL_VALUE_NOT_ALLOWED),
204 errmsg("jsonb subscript in assignment must not be null")));
206 return false;
207 }
208
209
210
211
212
213 if (workspace->indexOid[i] == INT4OID)
214 {
217
219 }
220 else
222 }
223 }
224
225 return true;
226}
227
228
229
230
231
232
233
234static void
238{
241 Jsonb *jsonbSource;
242
243
245
248 workspace->index,
251 false);
252}
253
254
255
256
257
258
259
260static void
264{
267 Jsonb *jsonbSource;
269
271 replacevalue.type = jbvNull;
272 else
274 &replacevalue);
275
276
277
278
279
281 {
283
284
285
286
287
288
290 {
292 newSource.val.array.nElems = 0;
293 newSource.val.array.rawScalar = false;
294 }
295 else
296 {
298 newSource.val.object.nPairs = 0;
299 }
300
303 }
304 else
306
308 workspace->index,
310 &replacevalue);
311
312}
313
314
315
316
317
318
319
320
321
322static void
326{
328
330 {
331
333 sbsrefstate->prevnull = true;
334 }
335 else
336 {
338
343 false);
344 }
345}
346
347
348
349
350
351
352static void
356{
360 char *ptr;
361
362
364 nupper * (sizeof(Datum) + sizeof(Oid)));
367
368
369
370
371
373 ptr += nupper * sizeof(Datum);
375
376 sbsrefstate->workspace = workspace;
377
378
380 {
383
385 }
386
387
388
389
394}
395
396
397
398
399
400
403{
407 .fetch_strict = true,
408 .fetch_leakproof = true,
409 .store_leakproof = false
410 };
411
413}
Datum idx(PG_FUNCTION_ARGS)
#define CStringGetTextDatum(s)
int errhint(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereport(elevel,...)
#define DirectFunctionCall1(func, arg1)
#define PG_RETURN_POINTER(x)
char * format_type_be(Oid type_oid)
Assert(PointerIsAligned(start, uint64))
Datum int4out(PG_FUNCTION_ARGS)
if(TABLE==NULL||TABLE_index==NULL)
static Jsonb * DatumGetJsonbP(Datum d)
void JsonbToJsonbValue(Jsonb *jsonb, JsonbValue *val)
Jsonb * JsonbValueToJsonb(JsonbValue *val)
static bool jsonb_subscript_check_subscripts(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void jsonb_subscript_transform(SubscriptingRef *sbsref, List *indirection, ParseState *pstate, bool isSlice, bool isAssignment)
Datum jsonb_subscript_handler(PG_FUNCTION_ARGS)
static void jsonb_subscript_assign(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void jsonb_subscript_fetch(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
static void jsonb_exec_setup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate, SubscriptExecSteps *methods)
struct JsonbSubWorkspace JsonbSubWorkspace
static void jsonb_subscript_fetch_old(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Datum jsonb_set_element(Jsonb *jb, Datum *path, int path_len, JsonbValue *newval)
Datum jsonb_get_element(Jsonb *jb, Datum *path, int npath, bool *isnull, bool as_text)
List * lappend(List *list, void *datum)
void * palloc0(Size size)
Oid exprType(const Node *expr)
int exprLocation(const Node *expr)
Node * coerce_type(ParseState *pstate, Node *node, Oid inputTypeId, Oid targetTypeId, int32 targetTypeMod, CoercionContext ccontext, CoercionForm cformat, int location)
bool can_coerce_type(int nargs, const Oid *input_typeids, const Oid *target_typeids, CoercionContext ccontext)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
int parser_errposition(ParseState *pstate, int location)
#define lfirst_node(type, lc)
#define foreach_current_index(var_or_cell)
static char * DatumGetCString(Datum X)
struct SubscriptingRefState * state
struct ExprEvalStep::@55::@83 sbsref_subscript
struct ExprEvalStep::@55::@84 sbsref
union ExprEvalStep::@55 d
ParseExprKind p_expr_kind
ExecEvalSubroutine sbs_fetch_old
ExecEvalBoolSubroutine sbs_check_subscripts
ExecEvalSubroutine sbs_assign
ExecEvalSubroutine sbs_fetch
SubscriptTransform transform