PostgreSQL Source Code git master
Loading...
Searching...
No Matches
arraysubs.c File Reference
#include "postgres.h"
#include "catalog/pg_type_d.h"
#include "executor/execExpr.h"
#include "nodes/makefuncs.h"
#include "nodes/nodeFuncs.h"
#include "nodes/subscripting.h"
#include "nodes/supportnodes.h"
#include "parser/parse_coerce.h"
#include "parser/parse_expr.h"
#include "utils/array.h"
#include "utils/fmgrprotos.h"
#include "utils/lsyscache.h"
Include dependency graph for arraysubs.c:

Go to the source code of this file.

Data Structures

struct  ArraySubWorkspace
 

Typedefs

typedef struct ArraySubWorkspace ArraySubWorkspace
 

Functions

static void array_subscript_transform (SubscriptingRef *sbsref, List *indirection, ParseState *pstate, bool isSlice, bool isAssignment)
 
static bool array_subscript_check_subscripts (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_fetch (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_fetch_slice (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_assign (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_assign_slice (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_fetch_old (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_subscript_fetch_old_slice (ExprState *state, ExprEvalStep *op, ExprContext *econtext)
 
static void array_exec_setup (const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate, SubscriptExecSteps *methods)
 
Datum array_subscript_handler (PG_FUNCTION_ARGS)
 
Datum raw_array_subscript_handler (PG_FUNCTION_ARGS)
 
Datum array_subscript_handler_support (PG_FUNCTION_ARGS)
 

Typedef Documentation

◆ ArraySubWorkspace

Function Documentation

◆ array_exec_setup()

static void array_exec_setup ( const SubscriptingRef sbsref,
SubscriptingRefState sbsrefstate,
SubscriptExecSteps methods 
)
static

Definition at line 475 of file arraysubs.c.

478{
479 bool is_slice = (sbsrefstate->numlower != 0);
480 ArraySubWorkspace *workspace;
481
482 /*
483 * Enforce the implementation limit on number of array subscripts. This
484 * check isn't entirely redundant with checking at parse time; conceivably
485 * the expression was stored by a backend with a different MAXDIM value.
486 */
487 if (sbsrefstate->numupper > MAXDIM)
490 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
491 sbsrefstate->numupper, MAXDIM)));
492
493 /* Should be impossible if parser is sane, but check anyway: */
494 if (sbsrefstate->numlower != 0 &&
495 sbsrefstate->numupper != sbsrefstate->numlower)
496 elog(ERROR, "upper and lower index lists are not same length");
497
498 /*
499 * Allocate type-specific workspace.
500 */
501 workspace = palloc_object(ArraySubWorkspace);
502 sbsrefstate->workspace = workspace;
503
504 /*
505 * Collect datatype details we'll need at execution.
506 */
507 workspace->refelemtype = sbsref->refelemtype;
508 workspace->refattrlength = get_typlen(sbsref->refcontainertype);
509 get_typlenbyvalalign(sbsref->refelemtype,
510 &workspace->refelemlength,
511 &workspace->refelembyval,
512 &workspace->refelemalign);
513
514 /*
515 * Pass back pointers to appropriate step execution functions.
516 */
518 if (is_slice)
519 {
523 }
524 else
525 {
529 }
530}
#define MAXDIM
Definition array.h:75
static void array_subscript_assign_slice(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:346
static void array_subscript_fetch_old(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:401
static void array_subscript_assign(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:296
static void array_subscript_fetch(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:238
static void array_subscript_fetch_old_slice(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:441
static void array_subscript_fetch_slice(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:266
static bool array_subscript_check_subscripts(ExprState *state, ExprEvalStep *op, ExprContext *econtext)
Definition arraysubs.c:182
int errcode(int sqlerrcode)
Definition elog.c:874
#define ERROR
Definition elog.h:39
#define elog(elevel,...)
Definition elog.h:227
#define ereport(elevel,...)
Definition elog.h:151
#define palloc_object(type)
Definition fe_memutils.h:74
void get_typlenbyvalalign(Oid typid, int16 *typlen, bool *typbyval, char *typalign)
Definition lsyscache.c:2491
int16 get_typlen(Oid typid)
Definition lsyscache.c:2417
static char * errmsg
static int fb(int x)
ExecEvalSubroutine sbs_fetch_old
Definition execExpr.h:817
ExecEvalBoolSubroutine sbs_check_subscripts
Definition execExpr.h:814
ExecEvalSubroutine sbs_assign
Definition execExpr.h:816
ExecEvalSubroutine sbs_fetch
Definition execExpr.h:815

References array_subscript_assign(), array_subscript_assign_slice(), array_subscript_check_subscripts(), array_subscript_fetch(), array_subscript_fetch_old(), array_subscript_fetch_old_slice(), array_subscript_fetch_slice(), elog, ereport, errcode(), errmsg, ERROR, fb(), get_typlen(), get_typlenbyvalalign(), MAXDIM, palloc_object, ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ArraySubWorkspace::refelemtype, SubscriptExecSteps::sbs_assign, SubscriptExecSteps::sbs_check_subscripts, SubscriptExecSteps::sbs_fetch, and SubscriptExecSteps::sbs_fetch_old.

Referenced by array_subscript_handler(), and raw_array_subscript_handler().

◆ array_subscript_assign()

static void array_subscript_assign ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 296 of file arraysubs.c.

299{
301 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
303
304 /*
305 * For an assignment to a fixed-length array type, both the original array
306 * and the value to be assigned into it must be non-NULL, else we punt and
307 * return the original array.
308 */
309 if (workspace->refattrlength > 0)
310 {
311 if (*op->resnull || sbsrefstate->replacenull)
312 return;
313 }
314
315 /*
316 * For assignment to varlena arrays, we handle a NULL original array by
317 * substituting an empty (zero-dimensional) array; insertion of the new
318 * element will result in a singleton array value. It does not matter
319 * whether the new element is NULL.
320 */
321 if (*op->resnull)
322 {
323 arraySource = PointerGetDatum(construct_empty_array(workspace->refelemtype));
324 *op->resnull = false;
325 }
326
328 sbsrefstate->numupper,
329 workspace->upperindex,
330 sbsrefstate->replacevalue,
331 sbsrefstate->replacenull,
332 workspace->refattrlength,
333 workspace->refelemlength,
334 workspace->refelembyval,
335 workspace->refelemalign);
336 /* The result is never NULL, so no need to change *op->resnull */
337}
ArrayType * construct_empty_array(Oid elmtype)
Datum array_set_element(Datum arraydatum, int nSubscripts, int *indx, Datum dataValue, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)
static Datum PointerGetDatum(const void *X)
Definition postgres.h:342
uint64_t Datum
Definition postgres.h:70
union ExprEvalStep::@61 d
struct SubscriptingRefState * state
Definition execExpr.h:570
struct ExprEvalStep::@61::@90 sbsref
Datum * resvalue
Definition execExpr.h:310
bool * resnull
Definition execExpr.h:311

References array_set_element(), construct_empty_array(), ExprEvalStep::d, fb(), PointerGetDatum(), ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ArraySubWorkspace::refelemtype, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_assign_slice()

static void array_subscript_assign_slice ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 346 of file arraysubs.c.

349{
351 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
353
354 /*
355 * For an assignment to a fixed-length array type, both the original array
356 * and the value to be assigned into it must be non-NULL, else we punt and
357 * return the original array.
358 */
359 if (workspace->refattrlength > 0)
360 {
361 if (*op->resnull || sbsrefstate->replacenull)
362 return;
363 }
364
365 /*
366 * For assignment to varlena arrays, we handle a NULL original array by
367 * substituting an empty (zero-dimensional) array; insertion of the new
368 * element will result in a singleton array value. It does not matter
369 * whether the new element is NULL.
370 */
371 if (*op->resnull)
372 {
373 arraySource = PointerGetDatum(construct_empty_array(workspace->refelemtype));
374 *op->resnull = false;
375 }
376
378 sbsrefstate->numupper,
379 workspace->upperindex,
380 workspace->lowerindex,
381 sbsrefstate->upperprovided,
382 sbsrefstate->lowerprovided,
383 sbsrefstate->replacevalue,
384 sbsrefstate->replacenull,
385 workspace->refattrlength,
386 workspace->refelemlength,
387 workspace->refelembyval,
388 workspace->refelemalign);
389 /* The result is never NULL, so no need to change *op->resnull */
390}
Datum array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, Datum srcArrayDatum, bool isNull, int arraytyplen, int elmlen, bool elmbyval, char elmalign)

References array_set_slice(), construct_empty_array(), ExprEvalStep::d, fb(), ArraySubWorkspace::lowerindex, PointerGetDatum(), ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ArraySubWorkspace::refelemtype, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_check_subscripts()

static bool array_subscript_check_subscripts ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 182 of file arraysubs.c.

185{
187 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
188
189 /* Process upper subscripts */
190 for (int i = 0; i < sbsrefstate->numupper; i++)
191 {
192 if (sbsrefstate->upperprovided[i])
193 {
194 /* If any index expr yields NULL, result is NULL or error */
195 if (sbsrefstate->upperindexnull[i])
196 {
197 if (sbsrefstate->isassignment)
200 errmsg("array subscript in assignment must not be null")));
201 *op->resnull = true;
202 return false;
203 }
204 workspace->upperindex[i] = DatumGetInt32(sbsrefstate->upperindex[i]);
205 }
206 }
207
208 /* Likewise for lower subscripts */
209 for (int i = 0; i < sbsrefstate->numlower; i++)
210 {
211 if (sbsrefstate->lowerprovided[i])
212 {
213 /* If any index expr yields NULL, result is NULL or error */
214 if (sbsrefstate->lowerindexnull[i])
215 {
216 if (sbsrefstate->isassignment)
219 errmsg("array subscript in assignment must not be null")));
220 *op->resnull = true;
221 return false;
222 }
223 workspace->lowerindex[i] = DatumGetInt32(sbsrefstate->lowerindex[i]);
224 }
225 }
226
227 return true;
228}
int i
Definition isn.c:77
static int32 DatumGetInt32(Datum X)
Definition postgres.h:202
struct ExprEvalStep::@61::@89 sbsref_subscript

References ExprEvalStep::d, DatumGetInt32(), ereport, errcode(), errmsg, ERROR, fb(), i, ArraySubWorkspace::lowerindex, ExprEvalStep::resnull, ExprEvalStep::sbsref_subscript, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_fetch()

static void array_subscript_fetch ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 238 of file arraysubs.c.

241{
243 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
244
245 /* Should not get here if source array (or any subscript) is null */
246 Assert(!(*op->resnull));
247
249 sbsrefstate->numupper,
250 workspace->upperindex,
251 workspace->refattrlength,
252 workspace->refelemlength,
253 workspace->refelembyval,
254 workspace->refelemalign,
255 op->resnull);
256}
Datum array_get_element(Datum arraydatum, int nSubscripts, int *indx, int arraytyplen, int elmlen, bool elmbyval, char elmalign, bool *isNull)
#define Assert(condition)
Definition c.h:943

References array_get_element(), Assert, ExprEvalStep::d, fb(), ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_fetch_old()

static void array_subscript_fetch_old ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 401 of file arraysubs.c.

404{
406 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
407
408 if (*op->resnull)
409 {
410 /* whole array is null, so any element is too */
411 sbsrefstate->prevvalue = (Datum) 0;
412 sbsrefstate->prevnull = true;
413 }
414 else
415 sbsrefstate->prevvalue = array_get_element(*op->resvalue,
416 sbsrefstate->numupper,
417 workspace->upperindex,
418 workspace->refattrlength,
419 workspace->refelemlength,
420 workspace->refelembyval,
421 workspace->refelemalign,
422 &sbsrefstate->prevnull);
423}

References array_get_element(), ExprEvalStep::d, fb(), ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_fetch_old_slice()

static void array_subscript_fetch_old_slice ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 441 of file arraysubs.c.

444{
446 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
447
448 if (*op->resnull)
449 {
450 /* whole array is null, so any slice is too */
451 sbsrefstate->prevvalue = (Datum) 0;
452 sbsrefstate->prevnull = true;
453 }
454 else
455 {
456 sbsrefstate->prevvalue = array_get_slice(*op->resvalue,
457 sbsrefstate->numupper,
458 workspace->upperindex,
459 workspace->lowerindex,
460 sbsrefstate->upperprovided,
461 sbsrefstate->lowerprovided,
462 workspace->refattrlength,
463 workspace->refelemlength,
464 workspace->refelembyval,
465 workspace->refelemalign);
466 /* slices of non-null arrays are never null */
467 sbsrefstate->prevnull = false;
468 }
469}
Datum array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, bool *upperProvided, bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, char elmalign)

References array_get_slice(), ExprEvalStep::d, fb(), ArraySubWorkspace::lowerindex, ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_fetch_slice()

static void array_subscript_fetch_slice ( ExprState state,
ExprEvalStep op,
ExprContext econtext 
)
static

Definition at line 266 of file arraysubs.c.

269{
271 ArraySubWorkspace *workspace = (ArraySubWorkspace *) sbsrefstate->workspace;
272
273 /* Should not get here if source array (or any subscript) is null */
274 Assert(!(*op->resnull));
275
277 sbsrefstate->numupper,
278 workspace->upperindex,
279 workspace->lowerindex,
280 sbsrefstate->upperprovided,
281 sbsrefstate->lowerprovided,
282 workspace->refattrlength,
283 workspace->refelemlength,
284 workspace->refelembyval,
285 workspace->refelemalign);
286 /* The slice is never NULL, so no need to change *op->resnull */
287}

References array_get_slice(), Assert, ExprEvalStep::d, fb(), ArraySubWorkspace::lowerindex, ArraySubWorkspace::refattrlength, ArraySubWorkspace::refelemalign, ArraySubWorkspace::refelembyval, ArraySubWorkspace::refelemlength, ExprEvalStep::resnull, ExprEvalStep::resvalue, ExprEvalStep::sbsref, ExprEvalStep::state, and ArraySubWorkspace::upperindex.

Referenced by array_exec_setup().

◆ array_subscript_handler()

Datum array_subscript_handler ( PG_FUNCTION_ARGS  )

Definition at line 541 of file arraysubs.c.

542{
543 static const SubscriptRoutines sbsroutines = {
545 .exec_setup = array_exec_setup,
546 .fetch_strict = true, /* fetch returns NULL for NULL inputs */
547 .fetch_leakproof = true, /* fetch returns NULL for bad subscript */
548 .store_leakproof = false /* ... but assignment throws error */
549 };
550
552}
static void array_exec_setup(const SubscriptingRef *sbsref, SubscriptingRefState *sbsrefstate, SubscriptExecSteps *methods)
Definition arraysubs.c:475
static void array_subscript_transform(SubscriptingRef *sbsref, List *indirection, ParseState *pstate, bool isSlice, bool isAssignment)
Definition arraysubs.c:57
#define PG_RETURN_POINTER(x)
Definition fmgr.h:363
SubscriptTransform transform

References array_exec_setup(), array_subscript_transform(), fb(), PG_RETURN_POINTER, and SubscriptRoutines::transform.

◆ array_subscript_handler_support()

Datum array_subscript_handler_support ( PG_FUNCTION_ARGS  )

Definition at line 587 of file arraysubs.c.

588{
590 Node *ret = NULL;
591
593 {
594 /*
595 * We can optimize in-place subscripted assignment if the refexpr is
596 * the array being assigned to. We don't need to worry about array
597 * references within the refassgnexpr or the subscripts; however, if
598 * there's no refassgnexpr then it's a fetch which there's no need to
599 * optimize.
600 */
602 Param *refexpr = (Param *) linitial(req->args);
603
604 if (refexpr && IsA(refexpr, Param) &&
605 refexpr->paramkind == PARAM_EXTERN &&
606 refexpr->paramid == req->paramid &&
607 lsecond(req->args) != NULL)
608 ret = (Node *) refexpr;
609 }
610
612}
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define IsA(nodeptr, _type_)
Definition nodes.h:164
#define linitial(l)
Definition pg_list.h:178
#define lsecond(l)
Definition pg_list.h:183
@ PARAM_EXTERN
Definition primnodes.h:385
Definition nodes.h:135
int paramid
Definition primnodes.h:397
ParamKind paramkind
Definition primnodes.h:396

References fb(), IsA, linitial, lsecond, PARAM_EXTERN, Param::paramid, Param::paramkind, PG_GETARG_POINTER, and PG_RETURN_POINTER.

◆ array_subscript_transform()

static void array_subscript_transform ( SubscriptingRef sbsref,
List indirection,
ParseState pstate,
bool  isSlice,
bool  isAssignment 
)
static

Definition at line 57 of file arraysubs.c.

62{
66
67 /*
68 * Transform the subscript expressions, and separate upper and lower
69 * bounds into two lists.
70 *
71 * If we have a container slice expression, we convert any non-slice
72 * indirection items to slices by treating the single subscript as the
73 * upper bound and supplying an assumed lower bound of 1.
74 */
75 foreach(idx, indirection)
76 {
78 Node *subexpr;
79
80 if (isSlice)
81 {
82 if (ai->lidx)
83 {
84 subexpr = transformExpr(pstate, ai->lidx, pstate->p_expr_kind);
85 /* If it's not int4 already, try to coerce */
86 subexpr = coerce_to_target_type(pstate,
87 subexpr, exprType(subexpr),
88 INT4OID, -1,
91 -1);
92 if (subexpr == NULL)
95 errmsg("array subscript must have type integer"),
96 parser_errposition(pstate, exprLocation(ai->lidx))));
97 }
98 else if (!ai->is_slice)
99 {
100 /* Make a constant 1 */
101 subexpr = (Node *) makeConst(INT4OID,
102 -1,
104 sizeof(int32),
105 Int32GetDatum(1),
106 false,
107 true); /* pass by value */
108 }
109 else
110 {
111 /* Slice with omitted lower bound, put NULL into the list */
112 subexpr = NULL;
113 }
115 }
116 else
117 Assert(ai->lidx == NULL && !ai->is_slice);
118
119 if (ai->uidx)
120 {
121 subexpr = transformExpr(pstate, ai->uidx, pstate->p_expr_kind);
122 /* If it's not int4 already, try to coerce */
123 subexpr = coerce_to_target_type(pstate,
124 subexpr, exprType(subexpr),
125 INT4OID, -1,
128 -1);
129 if (subexpr == NULL)
132 errmsg("array subscript must have type integer"),
133 parser_errposition(pstate, exprLocation(ai->uidx))));
134 }
135 else
136 {
137 /* Slice with omitted upper bound, put NULL into the list */
138 Assert(isSlice && ai->is_slice);
139 subexpr = NULL;
140 }
142 }
143
144 /* ... and store the transformed lists into the SubscriptingRef node */
147
148 /* Verify subscript list lengths are within implementation limit */
152 errmsg("number of array dimensions (%d) exceeds the maximum allowed (%d)",
154 /* We need not check lowerIndexpr separately */
155
156 /*
157 * Determine the result type of the subscripting operation. It's the same
158 * as the array type if we're slicing, else it's the element type. In
159 * either case, the typmod is the same as the array's, so we need not
160 * change reftypmod.
161 */
162 if (isSlice)
163 sbsref->refrestype = sbsref->refcontainertype;
164 else
165 sbsref->refrestype = sbsref->refelemtype;
166}
Datum idx(PG_FUNCTION_ARGS)
Definition _int_op.c:262
int32_t int32
Definition c.h:620
List * lappend(List *list, void *datum)
Definition list.c:339
Const * makeConst(Oid consttype, int32 consttypmod, Oid constcollid, int constlen, Datum constvalue, bool constisnull, bool constbyval)
Definition makefuncs.c:350
Oid exprType(const Node *expr)
Definition nodeFuncs.c:42
int exprLocation(const Node *expr)
Definition nodeFuncs.c:1392
Node * coerce_to_target_type(ParseState *pstate, Node *expr, Oid exprtype, Oid targettype, int32 targettypmod, CoercionContext ccontext, CoercionForm cformat, int location)
Node * transformExpr(ParseState *pstate, Node *expr, ParseExprKind exprKind)
Definition parse_expr.c:121
int parser_errposition(ParseState *pstate, int location)
Definition parse_node.c:106
#define lfirst_node(type, lc)
Definition pg_list.h:176
static int list_length(const List *l)
Definition pg_list.h:152
#define NIL
Definition pg_list.h:68
static Datum Int32GetDatum(int32 X)
Definition postgres.h:212
#define InvalidOid
@ COERCE_IMPLICIT_CAST
Definition primnodes.h:769
@ COERCION_ASSIGNMENT
Definition primnodes.h:748
Definition pg_list.h:54
ParseExprKind p_expr_kind
Definition parse_node.h:232
List * refupperindexpr
Definition primnodes.h:726
List * reflowerindexpr
Definition primnodes.h:732

References Assert, COERCE_IMPLICIT_CAST, coerce_to_target_type(), COERCION_ASSIGNMENT, ereport, errcode(), errmsg, ERROR, exprLocation(), exprType(), fb(), idx(), Int32GetDatum(), InvalidOid, lappend(), lfirst_node, list_length(), makeConst(), MAXDIM, NIL, ParseState::p_expr_kind, parser_errposition(), SubscriptingRef::reflowerindexpr, SubscriptingRef::refupperindexpr, and transformExpr().

Referenced by array_subscript_handler(), and raw_array_subscript_handler().

◆ raw_array_subscript_handler()

Datum raw_array_subscript_handler ( PG_FUNCTION_ARGS  )

Definition at line 568 of file arraysubs.c.

569{
570 static const SubscriptRoutines sbsroutines = {
572 .exec_setup = array_exec_setup,
573 .fetch_strict = true, /* fetch returns NULL for NULL inputs */
574 .fetch_leakproof = true, /* fetch returns NULL for bad subscript */
575 .store_leakproof = false /* ... but assignment throws error */
576 };
577
579}

References array_exec_setup(), array_subscript_transform(), fb(), PG_RETURN_POINTER, and SubscriptRoutines::transform.