80#define MUL_GUARD_DIGITS 4
81#define DIV_GUARD_DIGITS 8
90#define MUL_GUARD_DIGITS 3
91#define DIV_GUARD_DIGITS 6
98#define HALF_NBASE 5000
100#define MUL_GUARD_DIGITS 2
101#define DIV_GUARD_DIGITS 4
106#define NBASE_SQR (NBASE * NBASE)
168#define NUMERIC_SIGN_MASK 0xC000
169#define NUMERIC_POS 0x0000
170#define NUMERIC_NEG 0x4000
171#define NUMERIC_SHORT 0x8000
172#define NUMERIC_SPECIAL 0xC000
174#define NUMERIC_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_SIGN_MASK)
175#define NUMERIC_IS_SHORT(n) (NUMERIC_FLAGBITS(n) == NUMERIC_SHORT)
176#define NUMERIC_IS_SPECIAL(n) (NUMERIC_FLAGBITS(n) == NUMERIC_SPECIAL)
178#define NUMERIC_HDRSZ (VARHDRSZ + sizeof(uint16) + sizeof(int16))
179#define NUMERIC_HDRSZ_SHORT (VARHDRSZ + sizeof(uint16))
186#define NUMERIC_HEADER_IS_SHORT(n) (((n)->choice.n_header & 0x8000) != 0)
187#define NUMERIC_HEADER_SIZE(n) \
188 (VARHDRSZ + sizeof(uint16) + \
189 (NUMERIC_HEADER_IS_SHORT(n) ? 0 : sizeof(int16)))
200#define NUMERIC_EXT_SIGN_MASK 0xF000
201#define NUMERIC_NAN 0xC000
202#define NUMERIC_PINF 0xD000
203#define NUMERIC_NINF 0xF000
204#define NUMERIC_INF_SIGN_MASK 0x2000
206#define NUMERIC_EXT_FLAGBITS(n) ((n)->choice.n_header & NUMERIC_EXT_SIGN_MASK)
207#define NUMERIC_IS_NAN(n) ((n)->choice.n_header == NUMERIC_NAN)
208#define NUMERIC_IS_PINF(n) ((n)->choice.n_header == NUMERIC_PINF)
209#define NUMERIC_IS_NINF(n) ((n)->choice.n_header == NUMERIC_NINF)
210#define NUMERIC_IS_INF(n) \
211 (((n)->choice.n_header & ~NUMERIC_INF_SIGN_MASK) == NUMERIC_PINF)
217#define NUMERIC_SHORT_SIGN_MASK 0x2000
218#define NUMERIC_SHORT_DSCALE_MASK 0x1F80
219#define NUMERIC_SHORT_DSCALE_SHIFT 7
220#define NUMERIC_SHORT_DSCALE_MAX \
221 (NUMERIC_SHORT_DSCALE_MASK >> NUMERIC_SHORT_DSCALE_SHIFT)
222#define NUMERIC_SHORT_WEIGHT_SIGN_MASK 0x0040
223#define NUMERIC_SHORT_WEIGHT_MASK 0x003F
224#define NUMERIC_SHORT_WEIGHT_MAX NUMERIC_SHORT_WEIGHT_MASK
225#define NUMERIC_SHORT_WEIGHT_MIN (-(NUMERIC_SHORT_WEIGHT_MASK+1))
237#define NUMERIC_DSCALE_MASK 0x3FFF
238#define NUMERIC_DSCALE_MAX NUMERIC_DSCALE_MASK
240#define NUMERIC_SIGN(n) \
241 (NUMERIC_IS_SHORT(n) ? \
242 (((n)->choice.n_short.n_header & NUMERIC_SHORT_SIGN_MASK) ? \
243 NUMERIC_NEG : NUMERIC_POS) : \
244 (NUMERIC_IS_SPECIAL(n) ? \
245 NUMERIC_EXT_FLAGBITS(n) : NUMERIC_FLAGBITS(n)))
246#define NUMERIC_DSCALE(n) (NUMERIC_HEADER_IS_SHORT((n)) ? \
247 ((n)->choice.n_short.n_header & NUMERIC_SHORT_DSCALE_MASK) \
248 >> NUMERIC_SHORT_DSCALE_SHIFT \
249 : ((n)->choice.n_long.n_sign_dscale & NUMERIC_DSCALE_MASK))
250#define NUMERIC_WEIGHT(n) (NUMERIC_HEADER_IS_SHORT((n)) ? \
251 (((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_SIGN_MASK ? \
252 ~NUMERIC_SHORT_WEIGHT_MASK : 0) \
253 | ((n)->choice.n_short.n_header & NUMERIC_SHORT_WEIGHT_MASK)) \
254 : ((n)->choice.n_long.n_weight))
261#define NUMERIC_WEIGHT_MAX PG_INT16_MAX
405#define NumericAbbrevGetDatum(X) Int64GetDatum(X)
406#define DatumGetNumericAbbrev(X) DatumGetInt64(X)
407#define NUMERIC_ABBREV_NAN NumericAbbrevGetDatum(PG_INT64_MIN)
408#define NUMERIC_ABBREV_PINF NumericAbbrevGetDatum(-PG_INT64_MAX)
409#define NUMERIC_ABBREV_NINF NumericAbbrevGetDatum(PG_INT64_MAX)
474#define dump_numeric(s,n)
478#define digitbuf_alloc(ndigits) \
479 ((NumericDigit *) palloc((ndigits) * sizeof(NumericDigit)))
480#define digitbuf_free(buf) \
486#define init_var(v) memset(v, 0, sizeof(NumericVar))
488#define NUMERIC_DIGITS(num) (NUMERIC_HEADER_IS_SHORT(num) ? \
489 (num)->choice.n_short.n_data : (num)->choice.n_long.n_data)
490#define NUMERIC_NDIGITS(num) \
491 ((VARSIZE(num) - NUMERIC_HEADER_SIZE(num)) / sizeof(NumericDigit))
492#define NUMERIC_CAN_BE_SHORT(scale,weight) \
493 ((scale) <= NUMERIC_SHORT_DSCALE_MAX && \
494 (weight) <= NUMERIC_SHORT_WEIGHT_MAX && \
495 (weight) >= NUMERIC_SHORT_WEIGHT_MIN)
633 Node *escontext = fcinfo->context;
788 errmsg(
"invalid input syntax for type %s: \"%s\"",
871 return (
arg.ndigits == 0 ||
arg.ndigits <=
arg.weight + 1);
912 return ((typmod -
VARHDRSZ) >> 16) & 0xffff;
927 return (((typmod -
VARHDRSZ) & 0x7ff) ^ 1024) - 1024;
1040 while (
str[last] ==
'0')
1044 if (
str[last] ==
'.')
1048 str[last + 1] =
'\0';
1091 errmsg(
"invalid sign in external \"numeric\" value")));
1097 errmsg(
"invalid scale in external \"numeric\" value")));
1099 for (
i = 0;
i <
len;
i++)
1106 errmsg(
"invalid digit in external \"numeric\" value")));
1161 for (
i = 0;
i <
x.ndigits;
i++)
1282 new->choice.n_short.n_header =
1321 errmsg(
"NUMERIC precision %d must be between 1 and %d",
1326 errmsg(
"NUMERIC scale %d must be between %d and %d",
1335 errmsg(
"NUMERIC precision %d must be between 1 and %d",
1344 errmsg(
"invalid NUMERIC type modifier")));
1355 char *res = (
char *)
palloc(64);
1710 errmsg(
"start value cannot be NaN")));
1714 errmsg(
"start value cannot be infinity")));
1721 errmsg(
"stop value cannot be NaN")));
1725 errmsg(
"stop value cannot be infinity")));
1738 errmsg(
"step size cannot be NaN")));
1742 errmsg(
"step size cannot be infinity")));
1750 errmsg(
"step size cannot equal zero")));
1916 div_var(&res, &step, &res, 0,
false,
false);
1963 errmsg(
"count must be greater than zero")));
1970 errmsg(
"lower and upper bounds cannot be NaN")));
1975 errmsg(
"lower and upper bounds must be finite")));
1989 errmsg(
"lower bound cannot equal upper bound")));
2019 errmsg(
"integer out of range")));
2127 nss->input_count = 0;
2128 nss->estimating =
true;
2156 nss->input_count += 1;
2227 if (abbr_card > 100000.0)
2231 "numeric_abbrev: estimation ends at cardinality %f"
2233 abbr_card,
nss->input_count, memtupcount);
2234 nss->estimating =
false;
2251 "numeric_abbrev: aborting abbreviation at cardinality %f"
2252 " below threshold %f after " INT64_FORMAT " values (%d rows)",
2253 abbr_card,
nss->input_count / 10000.0 + 0.5,
2254 nss->input_count, memtupcount);
2260 "numeric_abbrev: cardinality %f"
2262 abbr_card,
nss->input_count, memtupcount);
2362 int weight = var->
weight;
2365 if (ndigits == 0 || weight < -44)
2369 else if (weight > 83)
2375 result = ((
int64) (weight + 44) << 56);
2398 if (
nss->estimating)
2596 errmsg(
"invalid preceding or following size in window function")));
3221 if (
arg2.ndigits == 0 ||
arg2.digits[0] == 0)
3238 errmsg(
"division by zero"));
3273 errmsg(
"division by zero")));
3291 errmsg(
"division by zero")));
3389 if (
arg2.ndigits == 0 ||
arg2.digits[0] == 0)
3403 errmsg(
"division by zero"));
3574 if (
arg1.ndigits == 0 ||
arg2.ndigits == 0)
3610 errmsg(
"factorial of a negative number is undefined")));
3620 errmsg(
"value overflows numeric format")));
3627 for (num = num - 1; num > 1; num--)
3670 errmsg(
"cannot take square root of a negative number")));
3691#if DEC_DIGITS == ((DEC_DIGITS / 2) * 2)
3694 if (
arg.weight >= 0)
3701 rscale =
Max(rscale,
arg.dscale);
3761 val *= 0.434294481903252;
3768 rscale =
Max(rscale,
arg.dscale);
3808 errmsg(
"cannot take logarithm of a negative number")));
3820 rscale =
Max(rscale,
arg.dscale);
3865 errmsg(
"cannot take logarithm of a negative number")));
3870 errmsg(
"cannot take logarithm of zero")));
3958 errmsg(
"zero raised to a negative power is undefined")));
3962 errmsg(
"a negative number raised to a non-integer power yields a complex result")));
4050 if (
arg2.ndigits > 0 &&
arg2.ndigits ==
arg2.weight + 1 &&
4051 (
arg2.digits[
arg2.ndigits - 1] & 1))
4070 errmsg(
"zero raised to a negative power is undefined")));
4217 errmsg(
"lower bound cannot be NaN"));
4221 errmsg(
"lower bound cannot be infinity"));
4228 errmsg(
"upper bound cannot be NaN"));
4232 errmsg(
"upper bound cannot be infinity"));
4311 static const int pow10[] = {1, 10, 100, 1000};
4312#elif DEC_DIGITS == 2
4313 static const int pow10[] = {1, 10};
4314#elif DEC_DIGITS == 1
4315 static const int pow10[] = {1};
4317#error unsupported NBASE
4374 errmsg(
"cannot convert NaN to %s",
"integer")));
4378 errmsg(
"cannot convert infinity to %s",
"integer")));
4387 errmsg(
"integer out of range")));
4444 errmsg(
"cannot convert NaN to %s",
"bigint")));
4448 errmsg(
"cannot convert infinity to %s",
"bigint")));
4457 errmsg(
"bigint out of range")));
4493 errmsg(
"cannot convert NaN to %s",
"smallint")));
4497 errmsg(
"cannot convert infinity to %s",
"smallint")));
4506 errmsg(
"smallint out of range")));
4511 errmsg(
"smallint out of range")));
4689 errmsg(
"cannot convert NaN to %s",
"pg_lsn")));
4693 errmsg(
"cannot convert infinity to %s",
"pg_lsn")));
4702 errmsg(
"pg_lsn out of range")));
4737#define NA_TOTAL_COUNT(na) \
4738 ((na)->N + (na)->NaNcount + (na)->pInfcount + (na)->nInfcount)
4752 elog(
ERROR,
"aggregate function called in non-aggregate context");
4757 state->calcSumX2 = calcSumX2;
4758 state->agg_context = agg_context;
4775 state->calcSumX2 = calcSumX2;
4810 if (
X.dscale >
state->maxScale)
4812 state->maxScale =
X.dscale;
4813 state->maxScaleCount = 1;
4815 else if (
X.dscale ==
state->maxScale)
4816 state->maxScaleCount++;
4819 if (
state->calcSumX2)
4833 if (
state->calcSumX2)
4883 if (
X.dscale ==
state->maxScale)
4885 if (
state->maxScaleCount > 1 ||
state->maxScale == 0)
4891 state->maxScaleCount--;
4893 else if (
state->N == 1)
4896 state->maxScale = 0;
4897 state->maxScaleCount = 0;
4907 if (
state->calcSumX2)
4922 if (
state->calcSumX2)
4935 if (
state->calcSumX2)
4976 elog(
ERROR,
"aggregate function called in non-aggregate context");
5068 elog(
ERROR,
"aggregate function called in non-aggregate context");
5141 elog(
ERROR,
"aggregate function called in non-aggregate context");
5192 elog(
ERROR,
"aggregate function called in non-aggregate context");
5251 elog(
ERROR,
"aggregate function called in non-aggregate context");
5306 elog(
ERROR,
"aggregate function called in non-aggregate context");
5367 elog(
ERROR,
"numeric_accum_inv called with NULL state");
5416 elog(
ERROR,
"aggregate function called in non-aggregate context");
5421 state->calcSumX2 = calcSumX2;
5438 state->calcSumX2 = calcSumX2;
5449 if (
state->calcSumX2)
5462 if (
state->calcSumX2)
5532 elog(
ERROR,
"aggregate function called in non-aggregate context");
5600 elog(
ERROR,
"aggregate function called in non-aggregate context");
5633 elog(
ERROR,
"aggregate function called in non-aggregate context");
5693 elog(
ERROR,
"aggregate function called in non-aggregate context");
5737 elog(
ERROR,
"aggregate function called in non-aggregate context");
5767 elog(
ERROR,
"aggregate function called in non-aggregate context");
5804 elog(
ERROR,
"int2_accum_inv called with NULL state");
5821 elog(
ERROR,
"int4_accum_inv called with NULL state");
5838 elog(
ERROR,
"int8_accum_inv called with NULL state");
5844 elog(
ERROR,
"do_numeric_discard failed unexpectedly");
5859 elog(
ERROR,
"int8_avg_accum_inv called with NULL state");
5931 if (
state->NaNcount > 0)
5935 if (
state->pInfcount > 0 &&
state->nInfcount > 0)
5937 if (
state->pInfcount > 0)
5939 if (
state->nInfcount > 0)
5965 if (
state->NaNcount > 0)
5969 if (
state->pInfcount > 0 &&
state->nInfcount > 0)
5971 if (
state->pInfcount > 0)
5973 if (
state->nInfcount > 0)
6031 if (
state->NaNcount > 0 ||
state->pInfcount > 0 ||
state->nInfcount > 0)
6047 rscale =
vsumX.dscale * 2;
6405 elog(
ERROR,
"expected 2-element int8 array");
6433 elog(
ERROR,
"expected 2-element int8 array");
6451 elog(
ERROR,
"aggregate function called in non-aggregate context");
6458 elog(
ERROR,
"expected 2-element int8 array");
6462 elog(
ERROR,
"expected 2-element int8 array");
6492 elog(
ERROR,
"expected 2-element int8 array");
6520 elog(
ERROR,
"expected 2-element int8 array");
6539 elog(
ERROR,
"expected 2-element int8 array");
6564 elog(
ERROR,
"expected 2-element int8 array");
6620 for (
i = 0;
i < ndigits;
i++)
6800 else if (*
cp ==
'.')
6810 else if (*
cp ==
'_')
6826 if (*
cp ==
'e' || *
cp ==
'E')
6844 else if (*
cp ==
'-')
6858 exponent = exponent * 10 + (*
cp++ -
'0');
6862 else if (*
cp ==
'_')
6874 exponent = -exponent;
6877 dscale -= (
int) exponent;
6897 dest->weight = weight;
6898 dest->dscale = dscale;
6903 while (ndigits-- > 0)
6908#elif DEC_DIGITS == 2
6910#elif DEC_DIGITS == 1
6913#error unsupported NBASE
6931 errmsg(
"value overflows numeric format")));
6936 errmsg(
"invalid input syntax for type %s: \"%s\"",
6947 return dig >=
'0' &&
dig <=
'9' ?
dig -
'0' :
6948 dig >=
'a' &&
dig <=
'f' ?
dig -
'a' + 10 :
6949 dig >=
'A' &&
dig <=
'F' ?
dig -
'A' + 10 : -1;
6974 const char **endptr,
Node *escontext)
7020 else if (*
cp ==
'_')
7035 if (*
cp >=
'0' && *
cp <=
'7')
7054 tmp = tmp * 8 + (*
cp++ -
'0');
7057 else if (*
cp ==
'_')
7061 if (*
cp <
'0' || *
cp >
'7')
7072 if (*
cp >=
'0' && *
cp <=
'1')
7091 tmp = tmp * 2 + (*
cp++ -
'0');
7094 else if (*
cp ==
'_')
7098 if (*
cp <
'0' || *
cp >
'1')
7134 errmsg(
"value overflows numeric format")));
7139 errmsg(
"invalid input syntax for type %s: \"%s\"",
7204 if (
value->ndigits > 0)
7212 dest->digits =
newbuf + 1;
7271 for (d = 0; d <= var->
weight; d++)
7277 bool putit = (d > 0);
7296#elif DEC_DIGITS == 2
7299 if (d1 > 0 || d > 0)
7302#elif DEC_DIGITS == 1
7305#error unsupported NBASE
7333#elif DEC_DIGITS == 2
7338#elif DEC_DIGITS == 1
7341#error unsupported NBASE
7482 for (
i = 0;
i <
len;
i++)
7513 int weight = var->
weight;
7543 while (n > 0 && *
digits == 0)
7550 while (n > 0 &&
digits[n - 1] == 0)
7566 result->choice.n_short.n_header =
7578 result->choice.n_long.n_sign_dscale =
7580 result->choice.n_long.n_weight = weight;
7592 errmsg(
"value overflows numeric format")));
7667 else if (
dig < 1000)
7669#elif DEC_DIGITS == 2
7672#elif DEC_DIGITS == 1
7675#error unsupported NBASE
7680 errmsg(
"numeric field overflow"),
7681 errdetail(
"A field with precision %d, scale %d must round to an absolute value less than %s%d.",
7731 errmsg(
"numeric field overflow"),
7732 errdetail(
"A field with precision %d, scale %d cannot hold an infinite value.",
7733 precision,
scale)));
7773 Assert(weight >= 0 && ndigits <= weight + 1);
7783 for (
i = 1;
i <= weight;
i++)
7856 var->
weight = ndigits - 1;
7901 Assert(weight >= 0 && ndigits <= weight + 1);
7906 for (
i = 1;
i <= weight;
i++)
7964 var->
weight = ndigits - 1;
7981 if (*endptr !=
'\0')
7986 errmsg(
"invalid input syntax for type %s: \"%s\"",
7987 "double precision", tmp)));
8498 for (i2 = 0; i2 <
i2limit; i2++)
8506 for (i1 = i1 - 1; i1 >= 0; i1--)
8539 for (i2 = 0; i2 <
i2limit; i2++)
8634#define PRODSUM1(v1,i1,v2,i2) ((v1)[(i1)] * (v2)[(i2)])
8635#define PRODSUM2(v1,i1,v2,i2) (PRODSUM1(v1,i1,v2,i2) + (v1)[(i1)+1] * (v2)[(i2)-1])
8636#define PRODSUM3(v1,i1,v2,i2) (PRODSUM2(v1,i1,v2,i2) + (v1)[(i1)+2] * (v2)[(i2)-2])
8637#define PRODSUM4(v1,i1,v2,i2) (PRODSUM3(v1,i1,v2,i2) + (v1)[(i1)+3] * (v2)[(i2)-3])
8638#define PRODSUM5(v1,i1,v2,i2) (PRODSUM4(v1,i1,v2,i2) + (v1)[(i1)+4] * (v2)[(i2)-4])
8639#define PRODSUM6(v1,i1,v2,i2) (PRODSUM5(v1,i1,v2,i2) + (v1)[(i1)+5] * (v2)[(i2)-5])
8878 int rscale,
bool round,
bool exact)
8911 errmsg(
"division by zero")));
9435 errmsg(
"division by zero"));
9551 errmsg(
"division by zero"));
9668 for (
i = 0;
i <
var1->ndigits;
i++)
9680 for (
i = 0;
i <
var2->ndigits;
i++)
9700 rscale =
Max(rscale,
var1->dscale);
9701 rscale =
Max(rscale,
var2->dscale);
9889 if (
cmp == 0 ||
var2->ndigits == 0)
9910 if (
mod.ndigits == 0)
9966 errmsg(
"cannot take square root of a negative number")));
9979 if (
arg->weight >= 0)
9990 if (rscale + 1 >= 0)
10140 while (step >= 0 && (
src_ndigits = ndigits[step]) <= 8)
10214 while (step >= 0 && (
src_ndigits = ndigits[step]) <= 16)
10440 errmsg(
"value overflows numeric format")));
10442 result->
dscale = rscale;
10501 add_var(result, &elem, result);
10513 while (
ndiv2-- > 0)
10637 errmsg(
"cannot take logarithm of zero")));
10641 errmsg(
"cannot take logarithm of a negative number")));
10716 add_var(result, &elem, result);
10813 if (
exp->ndigits == 0 ||
exp->ndigits <=
exp->weight + 1)
10854 if (
exp->ndigits > 0 &&
exp->ndigits >
exp->weight + 1)
10857 errmsg(
"a negative number raised to a non-integer power yields a complex result")));
10860 if (
exp->ndigits > 0 &&
exp->ndigits ==
exp->weight + 1 &&
10861 (
exp->digits[
exp->ndigits - 1] & 1))
10915 errmsg(
"value overflows numeric format")));
10921 val *= 0.434294481903252;
10926 rscale =
Max(rscale,
exp->dscale);
11009 errmsg(
"value overflows numeric format")));
11040 result->
dscale = rscale;
11050 mul_var(base, base, result, rscale);
11062 errmsg(
"division by zero")));
11064 result->
dscale = rscale;
11105 while ((mask >>= 1) > 0)
11144 errmsg(
"value overflows numeric format")));
11185 result->
digits[0] *= 10;
11213 errmsg(
"lower bound must be less than or equal to upper bound"));
11216 if (
rlen.ndigits == 0)
11219 result->
dscale = rscale;
11238 for (
i = 0;
i < n;
i++)
11284 result->
dscale = rscale;
11669#elif DEC_DIGITS == 2
11672#error unsupported NBASE
11675 digits[ndigits] -= extra;
11677 if (extra >=
pow10 / 2)
11769#elif DEC_DIGITS == 2
11772#error unsupported NBASE
11775 digits[ndigits] -= extra;
11794 while (ndigits > 0 && *
digits == 0)
11802 while (ndigits > 0 &&
digits[ndigits - 1] == 0)
11922 for (
i = ndigits - 1;
i >= 0;
i--)
11941 for (
i = ndigits - 1;
i >= 0;
i--)
#define PG_GETARG_ARRAYTYPE_P_COPY(n)
#define PG_GETARG_ARRAYTYPE_P(n)
#define PG_RETURN_ARRAYTYPE_P(x)
#define ARR_OVERHEAD_NONULLS(ndims)
int32 * ArrayGetIntegerTypmods(ArrayType *arr, int *n)
Datum numeric_stddev_samp(PG_FUNCTION_ARGS)
static const NumericVar const_two
static void mod_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
static const NumericVar const_pinf
static char * get_str_from_var_sci(const NumericVar *var, int rscale)
#define NUMERIC_INF_SIGN_MASK
#define dump_numeric(s, n)
#define NUMERIC_CAN_BE_SHORT(scale, weight)
static void ceil_var(const NumericVar *var, NumericVar *result)
static void accum_sum_carry(NumericSumAccum *accum)
#define DatumGetNumericAbbrev(X)
#define NUMERIC_HDRSZ_SHORT
Datum numeric_poly_var_samp(PG_FUNCTION_ARGS)
static const NumericDigit const_zero_point_nine_data[1]
char * numeric_normalize(Numeric num)
Datum numeric_accum(PG_FUNCTION_ARGS)
static void exp_var(const NumericVar *arg, NumericVar *result, int rscale)
Datum numeric_poly_serialize(PG_FUNCTION_ARGS)
Datum int2_accum_inv(PG_FUNCTION_ARGS)
static Datum numeric_abbrev_convert_var(const NumericVar *var, NumericSortSupport *nss)
Datum numeric_accum_inv(PG_FUNCTION_ARGS)
#define PRODSUM2(v1, i1, v2, i2)
char * numeric_out_sci(Numeric num, int scale)
Datum numeric_div(PG_FUNCTION_ARGS)
Datum numeric_sub(PG_FUNCTION_ARGS)
int32 numeric_maximum_size(int32 typmod)
static bool numeric_abbrev_abort(int memtupcount, SortSupport ssup)
Datum numeric_poly_var_pop(PG_FUNCTION_ARGS)
Datum numeric_avg_serialize(PG_FUNCTION_ARGS)
Datum hash_numeric(PG_FUNCTION_ARGS)
static Numeric make_result_safe(const NumericVar *var, Node *escontext)
Datum hash_numeric_extended(PG_FUNCTION_ARGS)
static bool numeric_is_integral(Numeric num)
static Int128AggState * makeInt128AggState(FunctionCallInfo fcinfo, bool calcSumX2)
Datum numeric_var_pop(PG_FUNCTION_ARGS)
static int get_min_scale(NumericVar *var)
static void sub_abs(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
static void power_var(const NumericVar *base, const NumericVar *exp, NumericVar *result)
static bool is_valid_numeric_typmod(int32 typmod)
static void div_var_int(const NumericVar *var, int ival, int ival_weight, NumericVar *result, int rscale, bool round)
static int cmp_numerics(Numeric num1, Numeric num2)
static NumericAggState * makeNumericAggState(FunctionCallInfo fcinfo, bool calcSumX2)
Datum numeric_avg(PG_FUNCTION_ARGS)
static void numericvar_serialize(StringInfo buf, const NumericVar *var)
static void accum_sum_final(NumericSumAccum *accum, NumericVar *result)
static void power_var_int(const NumericVar *base, int exp, int exp_dscale, NumericVar *result)
static void free_var(NumericVar *var)
#define NUMERIC_DSCALE(n)
Datum int2_sum(PG_FUNCTION_ARGS)
static int numeric_typmod_scale(int32 typmod)
Datum numeric_poly_sum(PG_FUNCTION_ARGS)
Datum int2_accum(PG_FUNCTION_ARGS)
Datum float8_numeric(PG_FUNCTION_ARGS)
#define PRODSUM3(v1, i1, v2, i2)
static void trunc_var(NumericVar *var, int rscale)
Datum numeric_round(PG_FUNCTION_ARGS)
static void set_var_from_num(Numeric num, NumericVar *dest)
static void accum_sum_add(NumericSumAccum *accum, const NumericVar *val)
Datum numeric_cmp(PG_FUNCTION_ARGS)
Datum int4_avg_combine(PG_FUNCTION_ARGS)
Datum width_bucket_numeric(PG_FUNCTION_ARGS)
Datum int8_sum(PG_FUNCTION_ARGS)
Datum int8_accum_inv(PG_FUNCTION_ARGS)
#define PRODSUM1(v1, i1, v2, i2)
Datum numerictypmodout(PG_FUNCTION_ARGS)
Datum generate_series_numeric_support(PG_FUNCTION_ARGS)
static Numeric duplicate_numeric(Numeric num)
static int32 make_numeric_typmod(int precision, int scale)
Datum numeric_recv(PG_FUNCTION_ARGS)
static void sub_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
Numeric int64_to_numeric(int64 val)
Datum numeric_trim_scale(PG_FUNCTION_ARGS)
Datum int2int4_sum(PG_FUNCTION_ARGS)
static Numeric numeric_stddev_internal(NumericAggState *state, bool variance, bool sample, bool *is_null)
Numeric random_numeric(pg_prng_state *state, Numeric rmin, Numeric rmax)
Datum float4_numeric(PG_FUNCTION_ARGS)
Datum numeric_poly_stddev_samp(PG_FUNCTION_ARGS)
static void add_abs(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
Datum generate_series_step_numeric(PG_FUNCTION_ARGS)
Datum numeric_int8(PG_FUNCTION_ARGS)
static void do_numeric_accum(NumericAggState *state, Numeric newval)
Datum int4_numeric(PG_FUNCTION_ARGS)
Datum numeric_sum(PG_FUNCTION_ARGS)
Datum numeric_ge(PG_FUNCTION_ARGS)
static const NumericVar const_ninf
Datum numeric_uplus(PG_FUNCTION_ARGS)
Datum numeric_stddev_pop(PG_FUNCTION_ARGS)
Datum numeric_uminus(PG_FUNCTION_ARGS)
static void add_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
static Datum numeric_abbrev_convert(Datum original_datum, SortSupport ssup)
static INT128 int128_deserialize(StringInfo buf)
Numeric numeric_mod_safe(Numeric num1, Numeric num2, Node *escontext)
#define NUMERIC_IS_SPECIAL(n)
#define NA_TOTAL_COUNT(na)
Datum numeric_le(PG_FUNCTION_ARGS)
Datum numeric_ceil(PG_FUNCTION_ARGS)
Datum numeric_send(PG_FUNCTION_ARGS)
static void gcd_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
static bool set_var_from_non_decimal_integer_str(const char *str, const char *cp, int sign, int base, NumericVar *dest, const char **endptr, Node *escontext)
int32 numeric_int4_safe(Numeric num, Node *escontext)
Datum numerictypmodin(PG_FUNCTION_ARGS)
Datum in_range_numeric_numeric(PG_FUNCTION_ARGS)
static void do_int128_discard(Int128AggState *state, int64 newval)
static Numeric numeric_poly_stddev_internal(Int128AggState *state, bool variance, bool sample, bool *is_null)
Datum numeric_power(PG_FUNCTION_ARGS)
Numeric numeric_add_safe(Numeric num1, Numeric num2, Node *escontext)
Numeric int64_div_fast_to_numeric(int64 val1, int log10val2)
#define PRODSUM5(v1, i1, v2, i2)
static const NumericVar const_minus_one
static bool numericvar_to_int32(const NumericVar *var, int32 *result)
int64 numeric_int8_safe(Numeric num, Node *escontext)
static int numeric_fast_cmp(Datum x, Datum y, SortSupport ssup)
static void floor_var(const NumericVar *var, NumericVar *result)
Datum numeric_int4(PG_FUNCTION_ARGS)
Datum numeric_gcd(PG_FUNCTION_ARGS)
static const NumericDigit const_one_data[1]
Datum numeric_poly_combine(PG_FUNCTION_ARGS)
static void init_var_from_num(Numeric num, NumericVar *dest)
static const NumericDigit const_two_data[1]
Numeric numeric_div_safe(Numeric num1, Numeric num2, Node *escontext)
Datum numeric_fac(PG_FUNCTION_ARGS)
Datum numeric_serialize(PG_FUNCTION_ARGS)
#define NUMERIC_SHORT_WEIGHT_MASK
#define NUMERIC_IS_PINF(n)
static void zero_var(NumericVar *var)
Datum numeric_ne(PG_FUNCTION_ARGS)
#define NUMERIC_SHORT_WEIGHT_SIGN_MASK
Datum int4_avg_accum_inv(PG_FUNCTION_ARGS)
static bool do_numeric_discard(NumericAggState *state, Numeric newval)
#define PRODSUM6(v1, i1, v2, i2)
Datum int8_avg_serialize(PG_FUNCTION_ARGS)
Datum numeric_exp(PG_FUNCTION_ARGS)
static int numeric_cmp_abbrev(Datum x, Datum y, SortSupport ssup)
Datum numeric_log(PG_FUNCTION_ARGS)
static void mul_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result, int rscale)
Datum numeric_scale(PG_FUNCTION_ARGS)
Datum numeric_sqrt(PG_FUNCTION_ARGS)
static bool apply_typmod_special(Numeric num, int32 typmod, Node *escontext)
Datum int4_accum_inv(PG_FUNCTION_ARGS)
Datum numeric_poly_deserialize(PG_FUNCTION_ARGS)
#define NUMERIC_IS_INF(n)
Datum numeric_inc(PG_FUNCTION_ARGS)
static void random_var(pg_prng_state *state, const NumericVar *rmin, const NumericVar *rmax, NumericVar *result)
static char * get_str_from_var(const NumericVar *var)
Numeric numeric_sub_safe(Numeric num1, Numeric num2, Node *escontext)
Datum int8_avg_accum_inv(PG_FUNCTION_ARGS)
Datum int4_accum(PG_FUNCTION_ARGS)
Datum generate_series_numeric(PG_FUNCTION_ARGS)
#define NUMERIC_ABBREV_PINF
static void compute_bucket(Numeric operand, Numeric bound1, Numeric bound2, const NumericVar *count_var, NumericVar *result_var)
Datum numeric_out(PG_FUNCTION_ARGS)
Datum numeric_int2(PG_FUNCTION_ARGS)
static void sqrt_var(const NumericVar *arg, NumericVar *result, int rscale)
Datum numeric_trunc(PG_FUNCTION_ARGS)
static bool set_var_from_str(const char *str, const char *cp, NumericVar *dest, const char **endptr, Node *escontext)
static int estimate_ln_dweight(const NumericVar *var)
Datum numeric_lcm(PG_FUNCTION_ARGS)
static int cmp_var(const NumericVar *var1, const NumericVar *var2)
Datum numeric_div_trunc(PG_FUNCTION_ARGS)
static int numeric_sign_internal(Numeric num)
Datum int8_accum(PG_FUNCTION_ARGS)
static NumericAggState * makeNumericAggStateCurrentContext(bool calcSumX2)
static int select_div_scale(const NumericVar *var1, const NumericVar *var2)
Datum numeric_avg_deserialize(PG_FUNCTION_ARGS)
static void mul_var_short(const NumericVar *var1, const NumericVar *var2, NumericVar *result)
#define NUMERIC_ABBREV_NAN
static int cmp_abs_common(const NumericDigit *var1digits, int var1ndigits, int var1weight, const NumericDigit *var2digits, int var2ndigits, int var2weight)
Datum numeric_poly_stddev_pop(PG_FUNCTION_ARGS)
static bool apply_typmod(NumericVar *var, int32 typmod, Node *escontext)
#define NUMERIC_IS_NINF(n)
Datum numeric_float8(PG_FUNCTION_ARGS)
Datum int2_avg_accum_inv(PG_FUNCTION_ARGS)
static const NumericVar const_zero_point_nine
static int cmp_abs(const NumericVar *var1, const NumericVar *var2)
static const NumericVar const_zero
Datum numeric_in(PG_FUNCTION_ARGS)
#define NUMERIC_ABBREV_NINF
static void accum_sum_combine(NumericSumAccum *accum, NumericSumAccum *accum2)
static void numericvar_deserialize(StringInfo buf, NumericVar *var)
static const int round_powers[4]
Datum numeric_mod(PG_FUNCTION_ARGS)
bool numeric_is_nan(Numeric num)
#define NUMERIC_SIGN_MASK
static void int128_serialize(StringInfo buf, INT128 val)
Datum numeric_lt(PG_FUNCTION_ARGS)
#define NUMERIC_DSCALE_MASK
Datum numeric_var_samp(PG_FUNCTION_ARGS)
Datum numeric_sortsupport(PG_FUNCTION_ARGS)
static void int64_to_numericvar(int64 val, NumericVar *var)
Datum int8_avg_deserialize(PG_FUNCTION_ARGS)
static void do_int128_accum(Int128AggState *state, int64 newval)
static bool numericvar_to_int64(const NumericVar *var, int64 *result)
Datum numeric_float8_no_overflow(PG_FUNCTION_ARGS)
Datum numeric_combine(PG_FUNCTION_ARGS)
Datum int8_avg_combine(PG_FUNCTION_ARGS)
Datum int8_avg_accum(PG_FUNCTION_ARGS)
#define PRODSUM4(v1, i1, v2, i2)
Datum numeric_sign(PG_FUNCTION_ARGS)
Datum int2_numeric(PG_FUNCTION_ARGS)
static int numeric_typmod_precision(int32 typmod)
#define NUMERIC_DSCALE_MAX
Datum int4_sum(PG_FUNCTION_ARGS)
static void alloc_var(NumericVar *var, int ndigits)
static int xdigit_value(char dig)
static Numeric make_result(const NumericVar *var)
static const NumericDigit const_one_point_one_data[2]
#define NumericAbbrevGetDatum(X)
#define NUMERIC_SHORT_DSCALE_SHIFT
static void accum_sum_reset(NumericSumAccum *accum)
#define NUMERIC_WEIGHT(n)
Datum numeric_add(PG_FUNCTION_ARGS)
static void round_var(NumericVar *var, int rscale)
Numeric numeric_mul_safe(Numeric num1, Numeric num2, Node *escontext)
Datum numeric_poly_avg(PG_FUNCTION_ARGS)
Datum numeric_eq(PG_FUNCTION_ARGS)
static void div_var(const NumericVar *var1, const NumericVar *var2, NumericVar *result, int rscale, bool round, bool exact)
static void set_var_from_var(const NumericVar *value, NumericVar *dest)
static void log_var(const NumericVar *base, const NumericVar *num, NumericVar *result)
Datum numeric_ln(PG_FUNCTION_ARGS)
#define NUMERIC_SHORT_SIGN_MASK
static bool numericvar_to_uint64(const NumericVar *var, uint64 *result)
Datum numeric_abs(PG_FUNCTION_ARGS)
Datum int8_avg(PG_FUNCTION_ARGS)
Datum numeric_avg_accum(PG_FUNCTION_ARGS)
static Int128AggState * makeInt128AggStateCurrentContext(bool calcSumX2)
Datum numeric_larger(PG_FUNCTION_ARGS)
static const NumericVar const_one_point_one
Datum int4_avg_accum(PG_FUNCTION_ARGS)
static void strip_var(NumericVar *var)
static const NumericVar const_nan
#define NUMERIC_IS_SHORT(n)
static void int128_to_numericvar(INT128 val, NumericVar *var)
Datum numeric_smaller(PG_FUNCTION_ARGS)
Datum numeric_gt(PG_FUNCTION_ARGS)
Datum numeric_deserialize(PG_FUNCTION_ARGS)
#define NUMERIC_DIGITS(num)
Datum int8_numeric(PG_FUNCTION_ARGS)
Datum numeric_mul(PG_FUNCTION_ARGS)
#define NUMERIC_IS_NAN(n)
static const NumericDigit const_zero_data[1]
static double numericvar_to_double_no_overflow(const NumericVar *var)
Datum numeric_avg_combine(PG_FUNCTION_ARGS)
Datum numeric_min_scale(PG_FUNCTION_ARGS)
#define NUMERIC_WEIGHT_MAX
Datum numeric_float4(PG_FUNCTION_ARGS)
Datum numeric_support(PG_FUNCTION_ARGS)
static const NumericVar const_one
#define NUMERIC_NDIGITS(num)
static void accum_sum_rescale(NumericSumAccum *accum, const NumericVar *val)
static int cmp_var_common(const NumericDigit *var1digits, int var1ndigits, int var1weight, int var1sign, const NumericDigit *var2digits, int var2ndigits, int var2weight, int var2sign)
bool numeric_is_inf(Numeric num)
static void ln_var(const NumericVar *arg, NumericVar *result, int rscale)
Datum numeric_pg_lsn(PG_FUNCTION_ARGS)
static void power_ten_int(int exp, NumericVar *result)
static void accum_sum_copy(NumericSumAccum *dst, NumericSumAccum *src)
Datum numeric_floor(PG_FUNCTION_ARGS)
Datum int2_avg_accum(PG_FUNCTION_ARGS)
static void div_mod_var(const NumericVar *var1, const NumericVar *var2, NumericVar *quot, NumericVar *rem)
#define Assert(condition)
#define FLEXIBLE_ARRAY_MEMBER
#define StaticAssertDecl(condition, errmessage)
Node * estimate_expression_value(PlannerInfo *root, Node *node)
int errdetail(const char *fmt,...)
int errcode(int sqlerrcode)
int errmsg(const char *fmt,...)
#define ereturn(context, dummy_value,...)
#define ereport(elevel,...)
#define palloc_object(type)
#define palloc0_object(type)
Datum float8in(PG_FUNCTION_ARGS)
Datum float4in(PG_FUNCTION_ARGS)
static float4 get_float4_infinity(void)
static float4 get_float4_nan(void)
static float8 get_float8_infinity(void)
static float8 get_float8_nan(void)
#define PG_FREE_IF_COPY(ptr, n)
#define PG_RETURN_UINT32(x)
#define PG_GETARG_BYTEA_PP(n)
#define PG_RETURN_BYTEA_P(x)
#define DirectFunctionCall2(func, arg1, arg2)
#define PG_GETARG_FLOAT8(n)
#define PG_RETURN_FLOAT8(x)
#define PG_GETARG_POINTER(n)
#define PG_RETURN_CSTRING(x)
#define PG_RETURN_INT64(x)
#define DirectFunctionCall1(func, arg1)
#define PG_GETARG_CSTRING(n)
#define PG_GETARG_INT64(n)
#define PG_DETOAST_DATUM_PACKED(datum)
#define PG_RETURN_UINT64(x)
#define PG_RETURN_INT16(x)
#define PG_RETURN_INT32(x)
#define PG_GETARG_INT32(n)
#define PG_GETARG_BOOL(n)
#define PG_RETURN_DATUM(x)
#define PG_GETARG_FLOAT4(n)
#define PG_RETURN_POINTER(x)
#define PG_RETURN_FLOAT4(x)
#define PG_RETURN_BOOL(x)
#define PG_GETARG_INT16(n)
#define SRF_IS_FIRSTCALL()
#define SRF_PERCALL_SETUP()
#define SRF_RETURN_NEXT(_funcctx, _result)
#define SRF_FIRSTCALL_INIT()
#define SRF_RETURN_DONE(_funcctx)
static Datum hash_uint32(uint32 k)
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
static Datum hash_any(const unsigned char *k, int keylen)
static const FormData_pg_attribute a1
void initHyperLogLog(hyperLogLogState *cState, uint8 bwidth)
double estimateHyperLogLog(hyperLogLogState *cState)
void addHyperLogLog(hyperLogLogState *cState, uint32 hash)
static INT128 make_int128(int64 hi, uint64 lo)
static bool int128_is_zero(INT128 x)
static void int128_sub_int64_mul_int64(INT128 *i128, int64 x, int64 y)
static int int128_sign(INT128 x)
static void int128_add_int128(INT128 *i128, INT128 v)
static void int128_sub_int64(INT128 *i128, int64 v)
static INT128 int64_to_int128(int64 v)
static void int128_add_int64(INT128 *i128, int64 v)
static void int128_div_mod_int32(INT128 *i128, int32 v, int32 *remainder)
static void int128_add_int64_mul_int64(INT128 *i128, int64 x, int64 y)
#define PG_INT128_HI_INT64(i128)
#define PG_INT128_LO_UINT64(i128)
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
static uint64 pg_abs_s64(int64 a)
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
static bool pg_add_u64_overflow(uint64 a, uint64 b, uint64 *result)
static bool pg_mul_u64_overflow(uint64 a, uint64 b, uint64 *result)
static uint32 pg_abs_s32(int32 a)
#define digitbuf_free(buf)
#define digitbuf_alloc(size)
char * pstrdup(const char *in)
void pfree(void *pointer)
void * palloc0(Size size)
MemoryContext CurrentMemoryContext
#define CHECK_FOR_INTERRUPTS()
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
int32 exprTypmod(const Node *expr)
Node * relabel_to_typmod(Node *expr, int32 typmod)
static bool is_funcclause(const void *clause)
#define IsA(nodeptr, _type_)
#define NUMERIC_MIN_SCALE
#define NUMERIC_MAX_PRECISION
#define NUMERIC_MAX_RESULT_SCALE
#define NUMERIC_MAX_DISPLAY_SCALE
#define NUMERIC_MIN_SIG_DIGITS
static Numeric DatumGetNumeric(Datum X)
#define PG_GETARG_NUMERIC(n)
struct NumericData * Numeric
#define NUMERIC_MAX_SCALE
#define NUMERIC_MIN_DISPLAY_SCALE
#define PG_RETURN_NUMERIC(x)
static Datum NumericGetDatum(Numeric X)
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
static int list_length(const List *l)
uint64 pg_prng_uint64_range(pg_prng_state *state, uint64 rmin, uint64 rmax)
static rewind_source * source
static char buf[DEFAULT_XLOG_SEG_SIZE]
int pg_strncasecmp(const char *s1, const char *s2, size_t n)
static uint32 DatumGetUInt32(Datum X)
static uint64 DatumGetUInt64(Datum X)
#define Int64GetDatumFast(X)
static Datum UInt64GetDatum(uint64 X)
static char * DatumGetCString(Datum X)
static Pointer DatumGetPointer(Datum X)
static Datum CStringGetDatum(const char *X)
static int32 DatumGetInt32(Datum X)
static int cmp(const chr *x, const chr *y, size_t len)
struct SortSupportData * SortSupport
struct StringInfoData * StringInfo
static void initReadOnlyStringInfo(StringInfo str, char *data, int len)
MemoryContext agg_context
union NumericChoice choice
NumericDigit n_data[FLEXIBLE_ARRAY_MEMBER]
NumericDigit n_data[FLEXIBLE_ARRAY_MEMBER]
hyperLogLogState abbr_card
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
struct NumericLong n_long
struct NumericShort n_short
static bool VARATT_IS_SHORT(const void *PTR)
static Size VARSIZE_ANY_EXHDR(const void *PTR)
static Size VARSIZE(const void *PTR)
static char * VARDATA(const void *PTR)
static char * VARDATA_ANY(const void *PTR)
static char * VARDATA_SHORT(const void *PTR)
static void SET_VARSIZE(void *PTR, Size len)
static Size VARSIZE_SHORT(const void *PTR)