@@ -311,7 +311,7 @@ transformArraySubscripts(ParseState *pstate,
311311 elementType = transformArrayType (& arrayType , & arrayTypMod );
312312
313313 /*
314- * A list containing only single subscripts refers to a single array
314+ * A list containing only single subscripts (uidx) refers to a single array
315315 * element. If any of the items are double subscripts (lower:upper), then
316316 * the subscript expression means an array slice operation. In this case,
317317 * we supply a default lower bound of 1 for any items that contain only a
@@ -322,7 +322,7 @@ transformArraySubscripts(ParseState *pstate,
322322 {
323323 A_Indices * ai = (A_Indices * ) lfirst (idx );
324324
325- if (ai -> lidx != NULL )
325+ if (ai -> lidx != NULL || ai -> lidx_default )
326326 {
327327 isSlice = true;
328328 break ;
@@ -335,9 +335,17 @@ transformArraySubscripts(ParseState *pstate,
335335 foreach (idx , indirection )
336336 {
337337 A_Indices * ai = (A_Indices * ) lfirst (idx );
338- Node * subexpr ;
338+ Node * subexpr = NULL ;
339339
340340 Assert (IsA (ai , A_Indices ));
341+ if ((ai -> uidx_default || ai -> lidx_default ) && assignFrom != NULL )
342+ ereport (ERROR ,
343+ (errcode (ERRCODE_ARRAY_SUBSCRIPT_ERROR ),
344+ errmsg ("array subscript must have both boundaries" ),
345+ errhint ("You can't omit the upper or lower"
346+ " boundaries when updating or inserting" ),
347+ parser_errposition (pstate , exprLocation (arrayBase ))));
348+
341349 if (isSlice )
342350 {
343351 if (ai -> lidx )
@@ -356,7 +364,7 @@ transformArraySubscripts(ParseState *pstate,
356364 errmsg ("array subscript must have type integer" ),
357365 parser_errposition (pstate , exprLocation (ai -> lidx ))));
358366 }
359- else
367+ else if ( ai -> lidx_default == false)
360368 {
361369 /* Make a constant 1 */
362370 subexpr = (Node * ) makeConst (INT4OID ,
@@ -369,19 +377,26 @@ transformArraySubscripts(ParseState *pstate,
369377 }
370378 lowerIndexpr = lappend (lowerIndexpr , subexpr );
371379 }
372- subexpr = transformExpr (pstate , ai -> uidx , pstate -> p_expr_kind );
373- /* If it's not int4 already, try to coerce */
374- subexpr = coerce_to_target_type (pstate ,
375- subexpr , exprType (subexpr ),
376- INT4OID , -1 ,
377- COERCION_ASSIGNMENT ,
378- COERCE_IMPLICIT_CAST ,
379- -1 );
380- if (subexpr == NULL )
381- ereport (ERROR ,
382- (errcode (ERRCODE_DATATYPE_MISMATCH ),
383- errmsg ("array subscript must have type integer" ),
384- parser_errposition (pstate , exprLocation (ai -> uidx ))));
380+
381+ if (ai -> uidx_default == false)
382+ {
383+ subexpr = transformExpr (pstate , ai -> uidx , pstate -> p_expr_kind );
384+ /* If it's not int4 already, try to coerce */
385+ subexpr = coerce_to_target_type (pstate ,
386+ subexpr , exprType (subexpr ),
387+ INT4OID , -1 ,
388+ COERCION_ASSIGNMENT ,
389+ COERCE_IMPLICIT_CAST ,
390+ -1 );
391+ if (subexpr == NULL )
392+ ereport (ERROR ,
393+ (errcode (ERRCODE_DATATYPE_MISMATCH ),
394+ errmsg ("array subscript must have type integer" ),
395+ parser_errposition (pstate , exprLocation (ai -> uidx ))));
396+ }
397+ else
398+ subexpr = NULL ;
399+
385400 upperIndexpr = lappend (upperIndexpr , subexpr );
386401 }
387402
0 commit comments