@@ -1995,6 +1995,8 @@ array_get_element_expanded(Datum arraydatum,
19951995 *nSubscripts: number of subscripts supplied (must be same for upper/lower)
19961996 *upperIndx[]: the upper subscript values
19971997 *lowerIndx[]: the lower subscript values
1998+ *upperProvided[]: true for provided upper subscript values
1999+ *lowerProvided[]: true for provided lower subscript values
19982000 *arraytyplen: pg_type.typlen for the array type
19992001 *elmlen: pg_type.typlen for the array's element type
20002002 *elmbyval: pg_type.typbyval for the array's element type
@@ -2003,6 +2005,9 @@ array_get_element_expanded(Datum arraydatum,
20032005 * Outputs:
20042006 *The return value is the new array Datum (it's never NULL)
20052007 *
2008+ * Omitted upper and lower subscript values are replaced by the corresponding
2009+ * array bound.
2010+ *
20062011 * NOTE: we assume it is OK to scribble on the provided subscript arrays
20072012 * lowerIndx[] and upperIndx[]. These are generally just temporaries.
20082013 */
@@ -2011,6 +2016,8 @@ array_get_slice(Datum arraydatum,
20112016int nSubscripts ,
20122017int * upperIndx ,
20132018int * lowerIndx ,
2019+ bool * upperProvided ,
2020+ bool * lowerProvided ,
20142021int arraytyplen ,
20152022int elmlen ,
20162023bool elmbyval ,
@@ -2081,9 +2088,9 @@ array_get_slice(Datum arraydatum,
20812088
20822089for (i = 0 ;i < nSubscripts ;i ++ )
20832090{
2084- if (lowerIndx [i ]< lb [i ])
2091+ if (! lowerProvided [ i ] || lowerIndx [i ]< lb [i ])
20852092lowerIndx [i ]= lb [i ];
2086- if (upperIndx [i ] >= (dim [i ]+ lb [i ]))
2093+ if (! upperProvided [ i ] || upperIndx [i ] >= (dim [i ]+ lb [i ]))
20872094upperIndx [i ]= dim [i ]+ lb [i ]- 1 ;
20882095if (lowerIndx [i ]> upperIndx [i ])
20892096return PointerGetDatum (construct_empty_array (elemtype ));
@@ -2708,6 +2715,8 @@ array_set_element_expanded(Datum arraydatum,
27082715 *nSubscripts: number of subscripts supplied (must be same for upper/lower)
27092716 *upperIndx[]: the upper subscript values
27102717 *lowerIndx[]: the lower subscript values
2718+ *upperProvided[]: true for provided upper subscript values
2719+ *lowerProvided[]: true for provided lower subscript values
27112720 *srcArrayDatum: the source for the inserted values
27122721 *isNull: indicates whether srcArrayDatum is NULL
27132722 *arraytyplen: pg_type.typlen for the array type
@@ -2719,6 +2728,9 @@ array_set_element_expanded(Datum arraydatum,
27192728 * A new array is returned, just like the old except for the
27202729 * modified range. The original array object is not changed.
27212730 *
2731+ * Omitted upper and lower subscript values are replaced by the corresponding
2732+ * array bound.
2733+ *
27222734 * For one-dimensional arrays only, we allow the array to be extended
27232735 * by assigning to positions outside the existing subscript range; any
27242736 * positions between the existing elements and the new ones are set to NULLs.
@@ -2735,6 +2747,8 @@ array_set_slice(Datum arraydatum,
27352747int nSubscripts ,
27362748int * upperIndx ,
27372749int * lowerIndx ,
2750+ bool * upperProvided ,
2751+ bool * lowerProvided ,
27382752Datum srcArrayDatum ,
27392753bool isNull ,
27402754int arraytyplen ,
@@ -2806,6 +2820,13 @@ array_set_slice(Datum arraydatum,
28062820
28072821for (i = 0 ;i < nSubscripts ;i ++ )
28082822{
2823+ if (!upperProvided [i ]|| !lowerProvided [i ])
2824+ ereport (ERROR ,
2825+ (errcode (ERRCODE_ARRAY_SUBSCRIPT_ERROR ),
2826+ errmsg ("array slice subscript must provide both boundaries" ),
2827+ errdetail ("When assigning to a slice of an empty array value,"
2828+ " slice boundaries must be fully specified." )));
2829+
28092830dim [i ]= 1 + upperIndx [i ]- lowerIndx [i ];
28102831lb [i ]= lowerIndx [i ];
28112832}
@@ -2839,6 +2860,10 @@ array_set_slice(Datum arraydatum,
28392860if (ndim == 1 )
28402861{
28412862Assert (nSubscripts == 1 );
2863+ if (!lowerProvided [0 ])
2864+ lowerIndx [0 ]= lb [0 ];
2865+ if (!upperProvided [0 ])
2866+ upperIndx [0 ]= dim [0 ]+ lb [0 ]- 1 ;
28422867if (lowerIndx [0 ]> upperIndx [0 ])
28432868ereport (ERROR ,
28442869(errcode (ERRCODE_ARRAY_SUBSCRIPT_ERROR ),
@@ -2867,6 +2892,10 @@ array_set_slice(Datum arraydatum,
28672892 */
28682893for (i = 0 ;i < nSubscripts ;i ++ )
28692894{
2895+ if (!lowerProvided [i ])
2896+ lowerIndx [i ]= lb [i ];
2897+ if (!upperProvided [i ])
2898+ upperIndx [i ]= dim [i ]+ lb [i ]- 1 ;
28702899if (lowerIndx [i ]> upperIndx [i ])
28712900ereport (ERROR ,
28722901(errcode (ERRCODE_ARRAY_SUBSCRIPT_ERROR ),