diff options
author | Pavan Deolasee | 2016-10-27 15:02:55 +0000 |
---|---|---|
committer | Pavan Deolasee | 2016-10-27 15:02:55 +0000 |
commit | c52792488cd87e67e62ec61f5b56f461900353b4 (patch) | |
tree | 02b4a719f979659de8f73fce6c1ca65cef2e323f /src/backend/utils/adt/arrayfuncs.c | |
parent | 891e6be57e5580b54a9df9fd42cb9bd10d0e7b21 (diff) | |
parent | b5bce6c1ec6061c8a4f730d927e162db7e2ce365 (diff) |
Merge commit 'b5bce6c1ec6061c8a4f730d927e162db7e2ce365'
Diffstat (limited to 'src/backend/utils/adt/arrayfuncs.c')
-rw-r--r-- | src/backend/utils/adt/arrayfuncs.c | 42 |
1 files changed, 34 insertions, 8 deletions
diff --git a/src/backend/utils/adt/arrayfuncs.c b/src/backend/utils/adt/arrayfuncs.c index 5eba10a805..8ee878e112 100644 --- a/src/backend/utils/adt/arrayfuncs.c +++ b/src/backend/utils/adt/arrayfuncs.c @@ -4,7 +4,7 @@ * Support functions for arrays. * * Portions Copyright (c) 2012-2014, TransLattice, Inc. - * Portions Copyright (c) 1996-2015, PostgreSQL Global Development Group + * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * @@ -21,9 +21,6 @@ #endif #include <math.h> -/* See arrayaccess.h */ -#define ARRAYACCESS_INCLUDE_DEFINITIONS - #include "access/htup_details.h" #include "catalog/pg_type.h" #include "funcapi.h" @@ -541,7 +538,7 @@ ArrayCount(const char *str, int *dim, char typdelim) errmsg("malformed array literal: \"%s\"", str), errdetail("Unexpected end of input."))); break; - case '\"': + case '"': /* * A quote must be after a level start, after a quoted @@ -825,7 +822,7 @@ ReadArrayStr(char *arrayStr, dstendptr = dstptr; hasquoting = true; /* can't be a NULL marker */ break; - case '\"': + case '"': in_quotes = !in_quotes; if (in_quotes) leadingspace = false; @@ -2021,6 +2018,8 @@ array_get_element_expanded(Datum arraydatum, * nSubscripts: number of subscripts supplied (must be same for upper/lower) * upperIndx[]: the upper subscript values * lowerIndx[]: the lower subscript values + * upperProvided[]: true for provided upper subscript values + * lowerProvided[]: true for provided lower subscript values * arraytyplen: pg_type.typlen for the array type * elmlen: pg_type.typlen for the array's element type * elmbyval: pg_type.typbyval for the array's element type @@ -2029,6 +2028,9 @@ array_get_element_expanded(Datum arraydatum, * Outputs: * The return value is the new array Datum (it's never NULL) * + * Omitted upper and lower subscript values are replaced by the corresponding + * array bound. + * * NOTE: we assume it is OK to scribble on the provided subscript arrays * lowerIndx[] and upperIndx[]. These are generally just temporaries. */ @@ -2037,6 +2039,8 @@ array_get_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, + bool *upperProvided, + bool *lowerProvided, int arraytyplen, int elmlen, bool elmbyval, @@ -2107,9 +2111,9 @@ array_get_slice(Datum arraydatum, for (i = 0; i < nSubscripts; i++) { - if (lowerIndx[i] < lb[i]) + if (!lowerProvided[i] || lowerIndx[i] < lb[i]) lowerIndx[i] = lb[i]; - if (upperIndx[i] >= (dim[i] + lb[i])) + if (!upperProvided[i] || upperIndx[i] >= (dim[i] + lb[i])) upperIndx[i] = dim[i] + lb[i] - 1; if (lowerIndx[i] > upperIndx[i]) return PointerGetDatum(construct_empty_array(elemtype)); @@ -2734,6 +2738,8 @@ array_set_element_expanded(Datum arraydatum, * nSubscripts: number of subscripts supplied (must be same for upper/lower) * upperIndx[]: the upper subscript values * lowerIndx[]: the lower subscript values + * upperProvided[]: true for provided upper subscript values + * lowerProvided[]: true for provided lower subscript values * srcArrayDatum: the source for the inserted values * isNull: indicates whether srcArrayDatum is NULL * arraytyplen: pg_type.typlen for the array type @@ -2745,6 +2751,9 @@ array_set_element_expanded(Datum arraydatum, * A new array is returned, just like the old except for the * modified range. The original array object is not changed. * + * Omitted upper and lower subscript values are replaced by the corresponding + * array bound. + * * For one-dimensional arrays only, we allow the array to be extended * by assigning to positions outside the existing subscript range; any * positions between the existing elements and the new ones are set to NULLs. @@ -2761,6 +2770,8 @@ array_set_slice(Datum arraydatum, int nSubscripts, int *upperIndx, int *lowerIndx, + bool *upperProvided, + bool *lowerProvided, Datum srcArrayDatum, bool isNull, int arraytyplen, @@ -2832,6 +2843,13 @@ array_set_slice(Datum arraydatum, for (i = 0; i < nSubscripts; i++) { + if (!upperProvided[i] || !lowerProvided[i]) + ereport(ERROR, + (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), + errmsg("array slice subscript must provide both boundaries"), + errdetail("When assigning to a slice of an empty array value," + " slice boundaries must be fully specified."))); + dim[i] = 1 + upperIndx[i] - lowerIndx[i]; lb[i] = lowerIndx[i]; } @@ -2865,6 +2883,10 @@ array_set_slice(Datum arraydatum, if (ndim == 1) { Assert(nSubscripts == 1); + if (!lowerProvided[0]) + lowerIndx[0] = lb[0]; + if (!upperProvided[0]) + upperIndx[0] = dim[0] + lb[0] - 1; if (lowerIndx[0] > upperIndx[0]) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), @@ -2893,6 +2915,10 @@ array_set_slice(Datum arraydatum, */ for (i = 0; i < nSubscripts; i++) { + if (!lowerProvided[i]) + lowerIndx[i] = lb[i]; + if (!upperProvided[i]) + upperIndx[i] = dim[i] + lb[i] - 1; if (lowerIndx[i] > upperIndx[i]) ereport(ERROR, (errcode(ERRCODE_ARRAY_SUBSCRIPT_ERROR), |