/* *in_rangesupportfunctionforint8. * *Note:weneedn'tsupplyint8_int4orint8_int2variants,asimplicit *coercionoftheoffsetvaluetakescareofthosescenariosjustaswell.
*/
Datum
in_range_int8_int8(PG_FUNCTION_ARGS)
{
int64 val = PG_GETARG_INT64(0);
int64 base = PG_GETARG_INT64(1);
int64 offset = PG_GETARG_INT64(2); bool sub = PG_GETARG_BOOL(3); bool less = PG_GETARG_BOOL(4);
int64 sum;
if (offset < 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
errmsg("invalid preceding or following size in window function")));
Datum
int8um(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(arg == PG_INT64_MIN))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
result = -arg;
PG_RETURN_INT64(result);
}
Datum
int8up(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
/* Special care needs to be taken with INT64_MIN. See comments above. */ if (arg1 == PG_INT64_MIN)
{ if (arg2 == 0 || arg2 == PG_INT64_MIN)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
/* If the result is INT64_MIN, it cannot be represented. */ if (unlikely(result == PG_INT64_MIN))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
if (result < 0)
result = -result;
PG_RETURN_INT64(result);
}
Datum
int8inc(PG_FUNCTION_ARGS)
{ /* *Whenint8ispass-by-reference,weprovidethisspecialcasetoavoid *pallocoverheadforCOUNT():whencalledasanaggregate,weknowthat *theargumentismodifiablelocalstorage,sojustupdateitin-place. *(Ifint8ispass-by-value,thenofcoursethisisuselessaswellas *incorrect,sojustifdefitout.)
*/ #ifndef USE_FLOAT8_BYVAL /* controls int8 too */ if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_POINTER(arg);
} else #endif
{ /* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
}
Datum
int8dec(PG_FUNCTION_ARGS)
{ /* *Whenint8ispass-by-reference,weprovidethisspecialcasetoavoid *pallocoverheadforCOUNT():whencalledasanaggregate,weknowthat *theargumentismodifiablelocalstorage,sojustupdateitin-place. *(Ifint8ispass-by-value,thenofcoursethisisuselessaswellas *incorrect,sojustifdefitout.)
*/ #ifndef USE_FLOAT8_BYVAL /* controls int8 too */ if (AggCheckCallContext(fcinfo, NULL))
{
int64 *arg = (int64 *) PG_GETARG_POINTER(0);
if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_POINTER(arg);
} else #endif
{ /* Not called as an aggregate, so just do it the dumb way */
int64 arg = PG_GETARG_INT64(0);
int64 result;
if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
if (IsA(rawreq, SupportRequestWFuncMonotonic))
{
SupportRequestWFuncMonotonic *req = (SupportRequestWFuncMonotonic *) rawreq;
MonotonicFunction monotonic = MONOTONICFUNC_NONE; int frameOptions = req->window_clause->frameOptions;
/* No ORDER BY clause then all rows are peers */ if (req->window_clause->orderClause == NIL)
monotonic = MONOTONICFUNC_BOTH; else
{ /* *Otherwisetakeintoaccounttheframeoptions.Whentheframe *boundisthestartofthewindowthentheresultingvaluecan *neverdecrease,thereforeismonotonicallyincreasing
*/ if (frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
monotonic |= MONOTONICFUNC_INCREASING;
if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64(result);
}
Datum
int48(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);
PG_RETURN_INT64((int64) arg);
}
Datum
int84(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32((int32) arg);
}
Datum
int28(PG_FUNCTION_ARGS)
{
int16 arg = PG_GETARG_INT16(0);
PG_RETURN_INT64((int64) arg);
}
Datum
int82(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16((int16) arg);
}
Datum
i8tod(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
float8 result;
result = arg;
PG_RETURN_FLOAT8(result);
}
/* dtoi8() *Convertfloat8to8-byteinteger.
*/
Datum
dtoi8(PG_FUNCTION_ARGS)
{
float8 num = PG_GETARG_FLOAT8(0);
/* *Getridofanyfractionalpartintheinput.Thisissowedon'tfail *onjust-out-of-rangevaluesthatwouldroundintorange.Note *assumptionthatrint()willpassthroughaNaNorInfunchanged.
*/
num = rint(num);
/* Range check */ if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64((int64) num);
}
Datum
i8tof(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
float4 result;
result = arg;
PG_RETURN_FLOAT4(result);
}
/* ftoi8() *Convertfloat4to8-byteinteger.
*/
Datum
ftoi8(PG_FUNCTION_ARGS)
{
float4 num = PG_GETARG_FLOAT4(0);
/* *Getridofanyfractionalpartintheinput.Thisissowedon'tfail *onjust-out-of-rangevaluesthatwouldroundintorange.Note *assumptionthatrint()willpassthroughaNaNorInfunchanged.
*/
num = rint(num);
/* Range check */ if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("bigint out of range")));
PG_RETURN_INT64((int64) num);
}
Datum
i8tooid(PG_FUNCTION_ARGS)
{
int64 arg = PG_GETARG_INT64(0);
if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("OID out of range")));
PG_RETURN_OID((Oid) arg);
}
Datum
oidtoi8(PG_FUNCTION_ARGS)
{
Oid arg = PG_GETARG_OID(0);
PG_RETURN_INT64((int64) arg);
}
/* *non-persistentnumericseriesgenerator
*/
Datum
generate_series_int8(PG_FUNCTION_ARGS)
{ return generate_series_step_int8(fcinfo);
}
/* stuff done only on the first call of the function */ if (SRF_IS_FIRSTCALL())
{
int64 start = PG_GETARG_INT64(0);
int64 finish = PG_GETARG_INT64(1);
int64 step = 1;
/* see if we were given an explicit step size */ if (PG_NARGS() == 3)
step = PG_GETARG_INT64(2); if (step == 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("step size cannot equal zero")));
/* create a function context for cross-call persistence */
funcctx = SRF_FIRSTCALL_INIT();
/* do when there is more left to send */
SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
} else /* do when there is no more left */
SRF_RETURN_DONE(funcctx);
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.