mirror of
https://github.com/postgres/postgres.git
synced 2025-12-01 12:18:01 +03:00
Make SQL arrays support null elements. This commit fixes the core array
functionality, but I still need to make another pass looking at places that incidentally use arrays (such as ACL manipulation) to make sure they are null-safe. Contrib needs work too. I have not changed the behaviors that are still under discussion about array comparison and what to do with lower bounds.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.127 2005/11/04 17:25:15 tgl Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/acl.c,v 1.128 2005/11/17 22:14:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -352,7 +352,7 @@ allocacl(int n)
|
||||
new_acl = (Acl *) palloc0(size);
|
||||
new_acl->size = size;
|
||||
new_acl->ndim = 1;
|
||||
new_acl->flags = 0;
|
||||
new_acl->dataoffset = 0; /* we never put in any nulls */
|
||||
new_acl->elemtype = ACLITEMOID;
|
||||
ARR_LBOUND(new_acl)[0] = 1;
|
||||
ARR_DIMS(new_acl)[0] = n;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
* Copyright (c) 2003-2005, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.16 2005/10/15 02:49:27 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/array_userfuncs.c,v 1.17 2005/11/17 22:14:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -19,6 +19,7 @@
|
||||
#include "utils/lsyscache.h"
|
||||
#include "utils/syscache.h"
|
||||
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
* array_push :
|
||||
* push an element onto either end of a one-dimensional array
|
||||
@@ -29,11 +30,11 @@ array_push(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ArrayType *v;
|
||||
Datum newelem;
|
||||
bool isNull;
|
||||
int *dimv,
|
||||
*lb;
|
||||
ArrayType *result;
|
||||
int indx;
|
||||
bool isNull;
|
||||
Oid element_type;
|
||||
int16 typlen;
|
||||
bool typbyval;
|
||||
@@ -54,15 +55,27 @@ array_push(PG_FUNCTION_ARGS)
|
||||
|
||||
if (arg0_elemid != InvalidOid)
|
||||
{
|
||||
v = PG_GETARG_ARRAYTYPE_P(0);
|
||||
element_type = ARR_ELEMTYPE(v);
|
||||
newelem = PG_GETARG_DATUM(1);
|
||||
if (PG_ARGISNULL(0))
|
||||
v = construct_empty_array(arg0_elemid);
|
||||
else
|
||||
v = PG_GETARG_ARRAYTYPE_P(0);
|
||||
isNull = PG_ARGISNULL(1);
|
||||
if (isNull)
|
||||
newelem = (Datum) 0;
|
||||
else
|
||||
newelem = PG_GETARG_DATUM(1);
|
||||
}
|
||||
else if (arg1_elemid != InvalidOid)
|
||||
{
|
||||
v = PG_GETARG_ARRAYTYPE_P(1);
|
||||
element_type = ARR_ELEMTYPE(v);
|
||||
newelem = PG_GETARG_DATUM(0);
|
||||
if (PG_ARGISNULL(1))
|
||||
v = construct_empty_array(arg1_elemid);
|
||||
else
|
||||
v = PG_GETARG_ARRAYTYPE_P(1);
|
||||
isNull = PG_ARGISNULL(0);
|
||||
if (isNull)
|
||||
newelem = (Datum) 0;
|
||||
else
|
||||
newelem = PG_GETARG_DATUM(0);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -73,6 +86,8 @@ array_push(PG_FUNCTION_ARGS)
|
||||
PG_RETURN_NULL(); /* keep compiler quiet */
|
||||
}
|
||||
|
||||
element_type = ARR_ELEMTYPE(v);
|
||||
|
||||
if (ARR_NDIM(v) == 1)
|
||||
{
|
||||
lb = ARR_LBOUND(v);
|
||||
@@ -84,11 +99,21 @@ array_push(PG_FUNCTION_ARGS)
|
||||
int ub = dimv[0] + lb[0] - 1;
|
||||
|
||||
indx = ub + 1;
|
||||
/* overflow? */
|
||||
if (indx < ub)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
||||
errmsg("integer out of range")));
|
||||
}
|
||||
else
|
||||
{
|
||||
/* prepend newelem */
|
||||
indx = lb[0] - 1;
|
||||
/* overflow? */
|
||||
if (indx > lb[0])
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
|
||||
errmsg("integer out of range")));
|
||||
}
|
||||
}
|
||||
else if (ARR_NDIM(v) == 0)
|
||||
@@ -108,7 +133,7 @@ array_push(PG_FUNCTION_ARGS)
|
||||
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
|
||||
sizeof(ArrayMetaState));
|
||||
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
|
||||
my_extra->element_type = InvalidOid;
|
||||
my_extra->element_type = ~element_type;
|
||||
}
|
||||
|
||||
if (my_extra->element_type != element_type)
|
||||
@@ -124,8 +149,8 @@ array_push(PG_FUNCTION_ARGS)
|
||||
typbyval = my_extra->typbyval;
|
||||
typalign = my_extra->typalign;
|
||||
|
||||
result = array_set(v, 1, &indx, newelem, -1,
|
||||
typlen, typbyval, typalign, &isNull);
|
||||
result = array_set(v, 1, &indx, newelem, isNull,
|
||||
-1, typlen, typbyval, typalign);
|
||||
|
||||
PG_RETURN_ARRAYTYPE_P(result);
|
||||
}
|
||||
@@ -141,26 +166,46 @@ array_cat(PG_FUNCTION_ARGS)
|
||||
{
|
||||
ArrayType *v1,
|
||||
*v2;
|
||||
ArrayType *result;
|
||||
int *dims,
|
||||
*lbs,
|
||||
ndims,
|
||||
nitems,
|
||||
ndatabytes,
|
||||
nbytes;
|
||||
int *dims1,
|
||||
*lbs1,
|
||||
ndims1,
|
||||
nitems1,
|
||||
ndatabytes1;
|
||||
int *dims2,
|
||||
*lbs2,
|
||||
ndims2,
|
||||
nitems2,
|
||||
ndatabytes2;
|
||||
int i;
|
||||
char *dat1,
|
||||
*dat2;
|
||||
bits8 *bitmap1,
|
||||
*bitmap2;
|
||||
Oid element_type;
|
||||
Oid element_type1;
|
||||
Oid element_type2;
|
||||
ArrayType *result;
|
||||
int32 dataoffset;
|
||||
|
||||
/* Concatenating a null array is a no-op, just return the other input */
|
||||
if (PG_ARGISNULL(0))
|
||||
{
|
||||
if (PG_ARGISNULL(1))
|
||||
PG_RETURN_NULL();
|
||||
result = PG_GETARG_ARRAYTYPE_P(1);
|
||||
PG_RETURN_ARRAYTYPE_P(result);
|
||||
}
|
||||
if (PG_ARGISNULL(1))
|
||||
{
|
||||
result = PG_GETARG_ARRAYTYPE_P(0);
|
||||
PG_RETURN_ARRAYTYPE_P(result);
|
||||
}
|
||||
|
||||
v1 = PG_GETARG_ARRAYTYPE_P(0);
|
||||
v2 = PG_GETARG_ARRAYTYPE_P(1);
|
||||
@@ -223,8 +268,12 @@ array_cat(PG_FUNCTION_ARGS)
|
||||
dims2 = ARR_DIMS(v2);
|
||||
dat1 = ARR_DATA_PTR(v1);
|
||||
dat2 = ARR_DATA_PTR(v2);
|
||||
ndatabytes1 = ARR_SIZE(v1) - ARR_OVERHEAD(ndims1);
|
||||
ndatabytes2 = ARR_SIZE(v2) - ARR_OVERHEAD(ndims2);
|
||||
bitmap1 = ARR_NULLBITMAP(v1);
|
||||
bitmap2 = ARR_NULLBITMAP(v2);
|
||||
nitems1 = ArrayGetNItems(ndims1, dims1);
|
||||
nitems2 = ArrayGetNItems(ndims2, dims2);
|
||||
ndatabytes1 = ARR_SIZE(v1) - ARR_DATA_OFFSET(v1);
|
||||
ndatabytes2 = ARR_SIZE(v2) - ARR_DATA_OFFSET(v2);
|
||||
|
||||
if (ndims1 == ndims2)
|
||||
{
|
||||
@@ -310,20 +359,41 @@ array_cat(PG_FUNCTION_ARGS)
|
||||
}
|
||||
}
|
||||
|
||||
/* Do this mainly for overflow checking */
|
||||
nitems = ArrayGetNItems(ndims, dims);
|
||||
|
||||
/* build the result array */
|
||||
ndatabytes = ndatabytes1 + ndatabytes2;
|
||||
nbytes = ndatabytes + ARR_OVERHEAD(ndims);
|
||||
if (ARR_HASNULL(v1) || ARR_HASNULL(v2))
|
||||
{
|
||||
dataoffset = ARR_OVERHEAD_WITHNULLS(ndims, nitems);
|
||||
nbytes = ndatabytes + dataoffset;
|
||||
}
|
||||
else
|
||||
{
|
||||
dataoffset = 0; /* marker for no null bitmap */
|
||||
nbytes = ndatabytes + ARR_OVERHEAD_NONULLS(ndims);
|
||||
}
|
||||
result = (ArrayType *) palloc(nbytes);
|
||||
|
||||
result->size = nbytes;
|
||||
result->ndim = ndims;
|
||||
result->flags = 0;
|
||||
result->dataoffset = dataoffset;
|
||||
result->elemtype = element_type;
|
||||
memcpy(ARR_DIMS(result), dims, ndims * sizeof(int));
|
||||
memcpy(ARR_LBOUND(result), lbs, ndims * sizeof(int));
|
||||
/* data area is arg1 then arg2 */
|
||||
memcpy(ARR_DATA_PTR(result), dat1, ndatabytes1);
|
||||
memcpy(ARR_DATA_PTR(result) + ndatabytes1, dat2, ndatabytes2);
|
||||
/* handle the null bitmap if needed */
|
||||
if (ARR_HASNULL(result))
|
||||
{
|
||||
array_bitmap_copy(ARR_NULLBITMAP(result), 0,
|
||||
bitmap1, 0,
|
||||
nitems1);
|
||||
array_bitmap_copy(ARR_NULLBITMAP(result), nitems1,
|
||||
bitmap2, 0,
|
||||
nitems2);
|
||||
}
|
||||
|
||||
PG_RETURN_ARRAYTYPE_P(result);
|
||||
}
|
||||
@@ -347,10 +417,6 @@ create_singleton_array(FunctionCallInfo fcinfo,
|
||||
int i;
|
||||
ArrayMetaState *my_extra;
|
||||
|
||||
if (element_type == 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
errmsg("invalid array element type OID: %u", element_type)));
|
||||
if (ndims < 1)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
|
||||
@@ -379,7 +445,7 @@ create_singleton_array(FunctionCallInfo fcinfo,
|
||||
fcinfo->flinfo->fn_extra = MemoryContextAlloc(fcinfo->flinfo->fn_mcxt,
|
||||
sizeof(ArrayMetaState));
|
||||
my_extra = (ArrayMetaState *) fcinfo->flinfo->fn_extra;
|
||||
my_extra->element_type = InvalidOid;
|
||||
my_extra->element_type = ~element_type;
|
||||
}
|
||||
|
||||
if (my_extra->element_type != element_type)
|
||||
@@ -395,6 +461,6 @@ create_singleton_array(FunctionCallInfo fcinfo,
|
||||
typbyval = my_extra->typbyval;
|
||||
typalign = my_extra->typalign;
|
||||
|
||||
return construct_md_array(dvalues, ndims, dims, lbs, element_type,
|
||||
return construct_md_array(dvalues, NULL, ndims, dims, lbs, element_type,
|
||||
typlen, typbyval, typalign);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.18 2004/12/31 22:01:21 pgsql Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/arrayutils.c,v 1.19 2005/11/17 22:14:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -16,11 +16,17 @@
|
||||
#include "postgres.h"
|
||||
|
||||
#include "utils/array.h"
|
||||
#include "utils/memutils.h"
|
||||
|
||||
|
||||
/* Convert subscript list into linear element number (from 0) */
|
||||
/*
|
||||
* Convert subscript list into linear element number (from 0)
|
||||
*
|
||||
* We assume caller has already range-checked the dimensions and subscripts,
|
||||
* so no overflow is possible.
|
||||
*/
|
||||
int
|
||||
ArrayGetOffset(int n, int *dim, int *lb, int *indx)
|
||||
ArrayGetOffset(int n, const int *dim, const int *lb, const int *indx)
|
||||
{
|
||||
int i,
|
||||
scale = 1,
|
||||
@@ -34,11 +40,12 @@ ArrayGetOffset(int n, int *dim, int *lb, int *indx)
|
||||
return offset;
|
||||
}
|
||||
|
||||
/* Same, but subscripts are assumed 0-based, and use a scale array
|
||||
/*
|
||||
* Same, but subscripts are assumed 0-based, and use a scale array
|
||||
* instead of raw dimension data (see mda_get_prod to create scale array)
|
||||
*/
|
||||
int
|
||||
ArrayGetOffset0(int n, int *tup, int *scale)
|
||||
ArrayGetOffset0(int n, const int *tup, const int *scale)
|
||||
{
|
||||
int i,
|
||||
lin = 0;
|
||||
@@ -48,24 +55,66 @@ ArrayGetOffset0(int n, int *tup, int *scale)
|
||||
return lin;
|
||||
}
|
||||
|
||||
/* Convert array dimensions into number of elements */
|
||||
/*
|
||||
* Convert array dimensions into number of elements
|
||||
*
|
||||
* This must do overflow checking, since it is used to validate that a user
|
||||
* dimensionality request doesn't overflow what we can handle.
|
||||
*
|
||||
* We limit array sizes to at most about a quarter billion elements,
|
||||
* so that it's not necessary to check for overflow in quite so many
|
||||
* places --- for instance when palloc'ing Datum arrays.
|
||||
*
|
||||
* The multiplication overflow check only works on machines that have int64
|
||||
* arithmetic, but that is nearly all platforms these days, and doing check
|
||||
* divides for those that don't seems way too expensive.
|
||||
*/
|
||||
int
|
||||
ArrayGetNItems(int ndim, int *dims)
|
||||
ArrayGetNItems(int ndim, const int *dims)
|
||||
{
|
||||
int i,
|
||||
ret;
|
||||
int32 ret;
|
||||
int i;
|
||||
|
||||
#define MaxArraySize ((Size) (MaxAllocSize / sizeof(Datum)))
|
||||
|
||||
if (ndim <= 0)
|
||||
return 0;
|
||||
ret = 1;
|
||||
for (i = 0; i < ndim; i++)
|
||||
ret *= dims[i];
|
||||
return ret;
|
||||
{
|
||||
int64 prod;
|
||||
|
||||
/* A negative dimension implies that UB-LB overflowed ... */
|
||||
if (dims[i] < 0)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("array size exceeds the maximum allowed (%d)",
|
||||
(int) MaxArraySize)));
|
||||
|
||||
prod = (int64) ret * (int64) dims[i];
|
||||
ret = (int32) prod;
|
||||
if ((int64) ret != prod)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("array size exceeds the maximum allowed (%d)",
|
||||
(int) MaxArraySize)));
|
||||
}
|
||||
Assert(ret >= 0);
|
||||
if ((Size) ret > MaxArraySize)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_PROGRAM_LIMIT_EXCEEDED),
|
||||
errmsg("array size exceeds the maximum allowed (%d)",
|
||||
(int) MaxArraySize)));
|
||||
return (int) ret;
|
||||
}
|
||||
|
||||
/* Compute ranges (sub-array dimensions) for an array slice */
|
||||
/*
|
||||
* Compute ranges (sub-array dimensions) for an array slice
|
||||
*
|
||||
* We assume caller has validated slice endpoints, so overflow is impossible
|
||||
*/
|
||||
void
|
||||
mda_get_range(int n, int *span, int *st, int *endp)
|
||||
mda_get_range(int n, int *span, const int *st, const int *endp)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -73,9 +122,13 @@ mda_get_range(int n, int *span, int *st, int *endp)
|
||||
span[i] = endp[i] - st[i] + 1;
|
||||
}
|
||||
|
||||
/* Compute products of array dimensions, ie, scale factors for subscripts */
|
||||
/*
|
||||
* Compute products of array dimensions, ie, scale factors for subscripts
|
||||
*
|
||||
* We assume caller has validated dimensions, so overflow is impossible
|
||||
*/
|
||||
void
|
||||
mda_get_prod(int n, int *range, int *prod)
|
||||
mda_get_prod(int n, const int *range, int *prod)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -84,11 +137,14 @@ mda_get_prod(int n, int *range, int *prod)
|
||||
prod[i] = prod[i + 1] * range[i + 1];
|
||||
}
|
||||
|
||||
/* From products of whole-array dimensions and spans of a sub-array,
|
||||
/*
|
||||
* From products of whole-array dimensions and spans of a sub-array,
|
||||
* compute offset distances needed to step through subarray within array
|
||||
*
|
||||
* We assume caller has validated dimensions, so overflow is impossible
|
||||
*/
|
||||
void
|
||||
mda_get_offset_values(int n, int *dist, int *prod, int *span)
|
||||
mda_get_offset_values(int n, int *dist, const int *prod, const int *span)
|
||||
{
|
||||
int i,
|
||||
j;
|
||||
@@ -102,16 +158,18 @@ mda_get_offset_values(int n, int *dist, int *prod, int *span)
|
||||
}
|
||||
}
|
||||
|
||||
/*-----------------------------------------------------------------------------
|
||||
generates the tuple that is lexicographically one greater than the current
|
||||
n-tuple in "curr", with the restriction that the i-th element of "curr" is
|
||||
less than the i-th element of "span".
|
||||
Returns -1 if no next tuple exists, else the subscript position (0..n-1)
|
||||
corresponding to the dimension to advance along.
|
||||
-----------------------------------------------------------------------------
|
||||
*/
|
||||
/*
|
||||
* Generates the tuple that is lexicographically one greater than the current
|
||||
* n-tuple in "curr", with the restriction that the i-th element of "curr" is
|
||||
* less than the i-th element of "span".
|
||||
*
|
||||
* Returns -1 if no next tuple exists, else the subscript position (0..n-1)
|
||||
* corresponding to the dimension to advance along.
|
||||
*
|
||||
* We assume caller has validated dimensions, so overflow is impossible
|
||||
*/
|
||||
int
|
||||
mda_next_tuple(int n, int *curr, int *span)
|
||||
mda_next_tuple(int n, int *curr, const int *span)
|
||||
{
|
||||
int i;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.115 2005/10/15 02:49:28 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/float.c,v 1.116 2005/11/17 22:14:52 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -1886,6 +1886,7 @@ check_float8_array(ArrayType *transarray, const char *caller)
|
||||
*/
|
||||
if (ARR_NDIM(transarray) != 1 ||
|
||||
ARR_DIMS(transarray)[0] != 3 ||
|
||||
ARR_HASNULL(transarray) ||
|
||||
ARR_ELEMTYPE(transarray) != FLOAT8OID)
|
||||
elog(ERROR, "%s: expected 3-element float8 array", caller);
|
||||
return (float8 *) ARR_DATA_PTR(transarray);
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.68 2005/10/15 02:49:28 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/int.c,v 1.69 2005/11/17 22:14:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -133,7 +133,7 @@ buildint2vector(const int2 *int2s, int n)
|
||||
*/
|
||||
result->size = Int2VectorSize(n);
|
||||
result->ndim = 1;
|
||||
result->flags = 0;
|
||||
result->dataoffset = 0; /* never any nulls */
|
||||
result->elemtype = INT2OID;
|
||||
result->dim1 = n;
|
||||
result->lbound1 = 0;
|
||||
@@ -171,7 +171,7 @@ int2vectorin(PG_FUNCTION_ARGS)
|
||||
|
||||
result->size = Int2VectorSize(n);
|
||||
result->ndim = 1;
|
||||
result->flags = 0;
|
||||
result->dataoffset = 0; /* never any nulls */
|
||||
result->elemtype = INT2OID;
|
||||
result->dim1 = n;
|
||||
result->lbound1 = 0;
|
||||
@@ -220,9 +220,9 @@ int2vectorrecv(PG_FUNCTION_ARGS)
|
||||
ObjectIdGetDatum(INT2OID),
|
||||
Int32GetDatum(-1)));
|
||||
/* sanity checks: int2vector must be 1-D, no nulls */
|
||||
if (result->ndim != 1 ||
|
||||
result->flags != 0 ||
|
||||
result->elemtype != INT2OID)
|
||||
if (ARR_NDIM(result) != 1 ||
|
||||
ARR_HASNULL(result) ||
|
||||
ARR_ELEMTYPE(result) != INT2OID)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
|
||||
errmsg("invalid int2vector data")));
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* Copyright (c) 1998-2005, PostgreSQL Global Development Group
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.86 2005/10/15 02:49:29 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/numeric.c,v 1.87 2005/11/17 22:14:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -2070,7 +2070,7 @@ do_numeric_accum(ArrayType *transarray, Numeric newval)
|
||||
/* We assume the input is array of numeric */
|
||||
deconstruct_array(transarray,
|
||||
NUMERICOID, -1, false, 'i',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 3)
|
||||
elog(ERROR, "expected 3-element numeric array");
|
||||
N = transdatums[0];
|
||||
@@ -2161,7 +2161,7 @@ numeric_avg(PG_FUNCTION_ARGS)
|
||||
/* We assume the input is array of numeric */
|
||||
deconstruct_array(transarray,
|
||||
NUMERICOID, -1, false, 'i',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 3)
|
||||
elog(ERROR, "expected 3-element numeric array");
|
||||
N = DatumGetNumeric(transdatums[0]);
|
||||
@@ -2197,7 +2197,7 @@ numeric_variance(PG_FUNCTION_ARGS)
|
||||
/* We assume the input is array of numeric */
|
||||
deconstruct_array(transarray,
|
||||
NUMERICOID, -1, false, 'i',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 3)
|
||||
elog(ERROR, "expected 3-element numeric array");
|
||||
N = DatumGetNumeric(transdatums[0]);
|
||||
@@ -2273,7 +2273,7 @@ numeric_stddev(PG_FUNCTION_ARGS)
|
||||
/* We assume the input is array of numeric */
|
||||
deconstruct_array(transarray,
|
||||
NUMERICOID, -1, false, 'i',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 3)
|
||||
elog(ERROR, "expected 3-element numeric array");
|
||||
N = DatumGetNumeric(transdatums[0]);
|
||||
@@ -2511,7 +2511,8 @@ int2_avg_accum(PG_FUNCTION_ARGS)
|
||||
else
|
||||
transarray = PG_GETARG_ARRAYTYPE_P_COPY(0);
|
||||
|
||||
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
|
||||
if (ARR_HASNULL(transarray) ||
|
||||
ARR_SIZE(transarray) != ARR_OVERHEAD_NONULLS(1) + sizeof(Int8TransTypeData))
|
||||
elog(ERROR, "expected 2-element int8 array");
|
||||
|
||||
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
|
||||
@@ -2538,7 +2539,8 @@ int4_avg_accum(PG_FUNCTION_ARGS)
|
||||
else
|
||||
transarray = PG_GETARG_ARRAYTYPE_P_COPY(0);
|
||||
|
||||
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
|
||||
if (ARR_HASNULL(transarray) ||
|
||||
ARR_SIZE(transarray) != ARR_OVERHEAD_NONULLS(1) + sizeof(Int8TransTypeData))
|
||||
elog(ERROR, "expected 2-element int8 array");
|
||||
|
||||
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
|
||||
@@ -2556,7 +2558,8 @@ int8_avg(PG_FUNCTION_ARGS)
|
||||
Datum countd,
|
||||
sumd;
|
||||
|
||||
if (ARR_SIZE(transarray) != ARR_OVERHEAD(1) + sizeof(Int8TransTypeData))
|
||||
if (ARR_HASNULL(transarray) ||
|
||||
ARR_SIZE(transarray) != ARR_OVERHEAD_NONULLS(1) + sizeof(Int8TransTypeData))
|
||||
elog(ERROR, "expected 2-element int8 array");
|
||||
transdata = (Int8TransTypeData *) ARR_DATA_PTR(transarray);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.64 2005/10/15 02:49:29 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/oid.c,v 1.65 2005/11/17 22:14:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -176,7 +176,7 @@ buildoidvector(const Oid *oids, int n)
|
||||
*/
|
||||
result->size = OidVectorSize(n);
|
||||
result->ndim = 1;
|
||||
result->flags = 0;
|
||||
result->dataoffset = 0; /* never any nulls */
|
||||
result->elemtype = OIDOID;
|
||||
result->dim1 = n;
|
||||
result->lbound1 = 0;
|
||||
@@ -213,7 +213,7 @@ oidvectorin(PG_FUNCTION_ARGS)
|
||||
|
||||
result->size = OidVectorSize(n);
|
||||
result->ndim = 1;
|
||||
result->flags = 0;
|
||||
result->dataoffset = 0; /* never any nulls */
|
||||
result->elemtype = OIDOID;
|
||||
result->dim1 = n;
|
||||
result->lbound1 = 0;
|
||||
@@ -262,9 +262,9 @@ oidvectorrecv(PG_FUNCTION_ARGS)
|
||||
ObjectIdGetDatum(OIDOID),
|
||||
Int32GetDatum(-1)));
|
||||
/* sanity checks: oidvector must be 1-D, no nulls */
|
||||
if (result->ndim != 1 ||
|
||||
result->flags != 0 ||
|
||||
result->elemtype != OIDOID)
|
||||
if (ARR_NDIM(result) != 1 ||
|
||||
ARR_HASNULL(result) ||
|
||||
ARR_ELEMTYPE(result) != OIDOID)
|
||||
ereport(ERROR,
|
||||
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
|
||||
errmsg("invalid oidvector data")));
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
* back to source text
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.207 2005/10/15 02:49:29 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/ruleutils.c,v 1.208 2005/11/17 22:14:53 tgl Exp $
|
||||
*
|
||||
* This software is copyrighted by Jan Wieck - Hamburg.
|
||||
*
|
||||
@@ -1107,7 +1107,7 @@ decompile_column_index_array(Datum column_index_array, Oid relId,
|
||||
/* Extract data from array of int16 */
|
||||
deconstruct_array(DatumGetArrayTypeP(column_index_array),
|
||||
INT2OID, 2, true, 's',
|
||||
&keys, &nKeys);
|
||||
&keys, NULL, &nKeys);
|
||||
|
||||
for (j = 0; j < nKeys; j++)
|
||||
{
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*
|
||||
*
|
||||
* IDENTIFICATION
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.157 2005/10/27 02:45:22 momjian Exp $
|
||||
* $PostgreSQL: pgsql/src/backend/utils/adt/timestamp.c,v 1.158 2005/11/17 22:14:53 tgl Exp $
|
||||
*
|
||||
*-------------------------------------------------------------------------
|
||||
*/
|
||||
@@ -2434,7 +2434,7 @@ interval_accum(PG_FUNCTION_ARGS)
|
||||
|
||||
deconstruct_array(transarray,
|
||||
INTERVALOID, sizeof(Interval), false, 'd',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 2)
|
||||
elog(ERROR, "expected 2-element interval array");
|
||||
|
||||
@@ -2475,7 +2475,7 @@ interval_avg(PG_FUNCTION_ARGS)
|
||||
|
||||
deconstruct_array(transarray,
|
||||
INTERVALOID, sizeof(Interval), false, 'd',
|
||||
&transdatums, &ndatums);
|
||||
&transdatums, NULL, &ndatums);
|
||||
if (ndatums != 2)
|
||||
elog(ERROR, "expected 2-element interval array");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user