#include "postgres.h"#include <ctype.h>#include <limits.h>#include "catalog/pg_type.h"#include "funcapi.h"#include "libpq/pqformat.h"#include "utils/array.h"#include "utils/builtins.h"
Go to the source code of this file.
Data Structures | |
| struct | generate_series_fctx |
Defines | |
| #define | SAMESIGN(a, b) (((a) < 0) == ((b) < 0)) |
| #define | Int2VectorSize(n) (offsetof(int2vector, values) + (n) * sizeof(int16)) |
Functions | |
| Datum | int2in (PG_FUNCTION_ARGS) |
| Datum | int2out (PG_FUNCTION_ARGS) |
| Datum | int2recv (PG_FUNCTION_ARGS) |
| Datum | int2send (PG_FUNCTION_ARGS) |
| int2vector * | buildint2vector (const int16 *int2s, int n) |
| Datum | int2vectorin (PG_FUNCTION_ARGS) |
| Datum | int2vectorout (PG_FUNCTION_ARGS) |
| Datum | int2vectorrecv (PG_FUNCTION_ARGS) |
| Datum | int2vectorsend (PG_FUNCTION_ARGS) |
| Datum | int2vectoreq (PG_FUNCTION_ARGS) |
| Datum | int4in (PG_FUNCTION_ARGS) |
| Datum | int4out (PG_FUNCTION_ARGS) |
| Datum | int4recv (PG_FUNCTION_ARGS) |
| Datum | int4send (PG_FUNCTION_ARGS) |
| Datum | i2toi4 (PG_FUNCTION_ARGS) |
| Datum | i4toi2 (PG_FUNCTION_ARGS) |
| Datum | int4_bool (PG_FUNCTION_ARGS) |
| Datum | bool_int4 (PG_FUNCTION_ARGS) |
| Datum | int4eq (PG_FUNCTION_ARGS) |
| Datum | int4ne (PG_FUNCTION_ARGS) |
| Datum | int4lt (PG_FUNCTION_ARGS) |
| Datum | int4le (PG_FUNCTION_ARGS) |
| Datum | int4gt (PG_FUNCTION_ARGS) |
| Datum | int4ge (PG_FUNCTION_ARGS) |
| Datum | int2eq (PG_FUNCTION_ARGS) |
| Datum | int2ne (PG_FUNCTION_ARGS) |
| Datum | int2lt (PG_FUNCTION_ARGS) |
| Datum | int2le (PG_FUNCTION_ARGS) |
| Datum | int2gt (PG_FUNCTION_ARGS) |
| Datum | int2ge (PG_FUNCTION_ARGS) |
| Datum | int24eq (PG_FUNCTION_ARGS) |
| Datum | int24ne (PG_FUNCTION_ARGS) |
| Datum | int24lt (PG_FUNCTION_ARGS) |
| Datum | int24le (PG_FUNCTION_ARGS) |
| Datum | int24gt (PG_FUNCTION_ARGS) |
| Datum | int24ge (PG_FUNCTION_ARGS) |
| Datum | int42eq (PG_FUNCTION_ARGS) |
| Datum | int42ne (PG_FUNCTION_ARGS) |
| Datum | int42lt (PG_FUNCTION_ARGS) |
| Datum | int42le (PG_FUNCTION_ARGS) |
| Datum | int42gt (PG_FUNCTION_ARGS) |
| Datum | int42ge (PG_FUNCTION_ARGS) |
| Datum | int4um (PG_FUNCTION_ARGS) |
| Datum | int4up (PG_FUNCTION_ARGS) |
| Datum | int4pl (PG_FUNCTION_ARGS) |
| Datum | int4mi (PG_FUNCTION_ARGS) |
| Datum | int4mul (PG_FUNCTION_ARGS) |
| Datum | int4div (PG_FUNCTION_ARGS) |
| Datum | int4inc (PG_FUNCTION_ARGS) |
| Datum | int2um (PG_FUNCTION_ARGS) |
| Datum | int2up (PG_FUNCTION_ARGS) |
| Datum | int2pl (PG_FUNCTION_ARGS) |
| Datum | int2mi (PG_FUNCTION_ARGS) |
| Datum | int2mul (PG_FUNCTION_ARGS) |
| Datum | int2div (PG_FUNCTION_ARGS) |
| Datum | int24pl (PG_FUNCTION_ARGS) |
| Datum | int24mi (PG_FUNCTION_ARGS) |
| Datum | int24mul (PG_FUNCTION_ARGS) |
| Datum | int24div (PG_FUNCTION_ARGS) |
| Datum | int42pl (PG_FUNCTION_ARGS) |
| Datum | int42mi (PG_FUNCTION_ARGS) |
| Datum | int42mul (PG_FUNCTION_ARGS) |
| Datum | int42div (PG_FUNCTION_ARGS) |
| Datum | int4mod (PG_FUNCTION_ARGS) |
| Datum | int2mod (PG_FUNCTION_ARGS) |
| Datum | int4abs (PG_FUNCTION_ARGS) |
| Datum | int2abs (PG_FUNCTION_ARGS) |
| Datum | int2larger (PG_FUNCTION_ARGS) |
| Datum | int2smaller (PG_FUNCTION_ARGS) |
| Datum | int4larger (PG_FUNCTION_ARGS) |
| Datum | int4smaller (PG_FUNCTION_ARGS) |
| Datum | int4and (PG_FUNCTION_ARGS) |
| Datum | int4or (PG_FUNCTION_ARGS) |
| Datum | int4xor (PG_FUNCTION_ARGS) |
| Datum | int4shl (PG_FUNCTION_ARGS) |
| Datum | int4shr (PG_FUNCTION_ARGS) |
| Datum | int4not (PG_FUNCTION_ARGS) |
| Datum | int2and (PG_FUNCTION_ARGS) |
| Datum | int2or (PG_FUNCTION_ARGS) |
| Datum | int2xor (PG_FUNCTION_ARGS) |
| Datum | int2not (PG_FUNCTION_ARGS) |
| Datum | int2shl (PG_FUNCTION_ARGS) |
| Datum | int2shr (PG_FUNCTION_ARGS) |
| Datum | generate_series_int4 (PG_FUNCTION_ARGS) |
| Datum | generate_series_step_int4 (PG_FUNCTION_ARGS) |
| #define Int2VectorSize | ( | n | ) | (offsetof(int2vector, values) + (n) * sizeof(int16)) |
Definition at line 43 of file int.c.
Referenced by buildint2vector(), and int2vectorin().
| #define SAMESIGN | ( | a, | ||
| b | ||||
| ) | (((a) < 0) == ((b) < 0)) |
| Datum bool_int4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 366 of file int.c.
References PG_GETARG_BOOL, and PG_RETURN_INT32.
{
if (PG_GETARG_BOOL(0) == false)
PG_RETURN_INT32(0);
else
PG_RETURN_INT32(1);
}
| int2vector* buildint2vector | ( | const int16 * | int2s, | |
| int | n | |||
| ) |
Definition at line 112 of file int.c.
References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), SET_VARSIZE, and int2vector::values.
Referenced by CreateTrigger(), and UpdateIndexRelation().
{
int2vector *result;
result = (int2vector *) palloc0(Int2VectorSize(n));
if (n > 0 && int2s)
memcpy(result->values, int2s, n * sizeof(int16));
/*
* Attach standard array header. For historical reasons, we set the index
* lower bound to 0 not 1.
*/
SET_VARSIZE(result, Int2VectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = INT2OID;
result->dim1 = n;
result->lbound1 = 0;
return result;
}
| Datum generate_series_int4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1336 of file int.c.
References generate_series_step_int4().
{
return generate_series_step_int4(fcinfo);
}
| Datum generate_series_step_int4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1342 of file int.c.
References generate_series_fctx::current, ereport, errcode(), errmsg(), ERROR, generate_series_fctx::finish, Int32GetDatum, MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), PG_GETARG_INT32, PG_NARGS, SAMESIGN, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, generate_series_fctx::step, and FuncCallContext::user_fctx.
Referenced by generate_series_int4().
{
FuncCallContext *funcctx;
generate_series_fctx *fctx;
int32 result;
MemoryContext oldcontext;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
{
int32 start = PG_GETARG_INT32(0);
int32 finish = PG_GETARG_INT32(1);
int32 step = 1;
/* see if we were given an explicit step size */
if (PG_NARGS() == 3)
step = PG_GETARG_INT32(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();
/*
* switch to memory context appropriate for multiple function calls
*/
oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
/* allocate memory for user context */
fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
/*
* Use fctx to keep state from call to call. Seed current with the
* original start value
*/
fctx->current = start;
fctx->finish = finish;
fctx->step = step;
funcctx->user_fctx = fctx;
MemoryContextSwitchTo(oldcontext);
}
/* stuff done on every call of the function */
funcctx = SRF_PERCALL_SETUP();
/*
* get the saved state and use current as the result for this iteration
*/
fctx = funcctx->user_fctx;
result = fctx->current;
if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
(fctx->step < 0 && fctx->current >= fctx->finish))
{
/* increment current in preparation for next iteration */
fctx->current += fctx->step;
/* if next-value computation overflows, this is the final result */
if (SAMESIGN(result, fctx->step) && !SAMESIGN(result, fctx->current))
fctx->step = 0;
/* do when there is more left to send */
SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
}
else
/* do when there is no more left */
SRF_RETURN_DONE(funcctx);
}
| Datum i2toi4 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 334 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT32.
{
int16 arg1 = PG_GETARG_INT16(0);
PG_RETURN_INT32((int32) arg1);
}
| Datum i4toi2 | ( | PG_FUNCTION_ARGS | ) |
Definition at line 342 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, and PG_RETURN_INT16.
{
int32 arg1 = PG_GETARG_INT32(0);
if (arg1 < SHRT_MIN || arg1 > SHRT_MAX)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16((int16) arg1);
}
| Datum int24div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 960 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and PG_RETURN_NULL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/* No overflow is possible */
PG_RETURN_INT32((int32) arg1 / arg2);
}
| Datum int24eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 498 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 == arg2);
}
| Datum int24ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 543 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 >= arg2);
}
| Datum int24gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 534 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 > arg2);
}
| Datum int24le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 525 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 <= arg2);
}
| Datum int24lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 516 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 < arg2);
}
| Datum int24mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 912 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 - arg2;
/*
* Overflow check. If the inputs are of the same sign then their
* difference cannot overflow. If they are of different signs then the
* result should be of the same sign as the first input.
*/
if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int24mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 933 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 * arg2;
/*
* Overflow check. We basically check to see if result / arg2 gives arg1
* again. There is one case where this fails: arg2 = 0 (which cannot
* overflow).
*
* Since the division is likely much more expensive than the actual
* multiplication, we'd like to skip it where possible. The best bang for
* the buck seems to be to check whether both inputs are in the int16
* range; if so, no overflow is possible.
*/
if (!(arg2 >= (int32) SHRT_MIN && arg2 <= (int32) SHRT_MAX) &&
result / arg2 != arg1)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int24ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 507 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 != arg2);
}
| Datum int24pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 891 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 + arg2;
/*
* Overflow check. If the inputs are of different signs then their sum
* cannot overflow. If the inputs are of the same sign, their sum had
* better be that sign too.
*/
if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int2abs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1164 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 result;
result = (arg1 < 0) ? -arg1 : arg1;
/* overflow check (needed for SHRT_MIN) */
if (result < 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16(result);
}
| Datum int2and | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1279 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_INT16(arg1 & arg2);
}
| Datum int2div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 851 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, PG_RETURN_NULL, and SAMESIGN.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
int16 result;
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/*
* SHRT_MIN / -1 is problematic, since the result can't be represented on
* a two's-complement machine. Some machines produce SHRT_MIN, some
* produce zero, some throw an exception. We can dodge the problem by
* recognizing that division by -1 is the same as negation.
*/
if (arg2 == -1)
{
result = -arg1;
/* overflow check (needed for SHRT_MIN) */
if (arg1 != 0 && SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16(result);
}
/* No overflow is possible */
result = arg1 / arg2;
PG_RETURN_INT16(result);
}
| Datum int2eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 444 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 == arg2);
}
| Datum int2ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 489 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 >= arg2);
}
| Datum int2gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 480 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 > arg2);
}
| Datum int2in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 61 of file int.c.
References pg_atoi(), PG_GETARG_CSTRING, and PG_RETURN_INT16.
{
char *num = PG_GETARG_CSTRING(0);
PG_RETURN_INT16(pg_atoi(num, sizeof(int16), '\0'));
}
| Datum int2larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1179 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_INT16((arg1 > arg2) ? arg1 : arg2);
}
| Datum int2le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 471 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 <= arg2);
}
| Datum int2lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 462 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 < arg2);
}
| Datum int2mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 809 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, and SAMESIGN.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
int16 result;
result = arg1 - arg2;
/*
* Overflow check. If the inputs are of the same sign then their
* difference cannot overflow. If they are of different signs then the
* result should be of the same sign as the first input.
*/
if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16(result);
}
| Datum int2mod | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1116 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, and PG_RETURN_NULL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/*
* Some machines throw a floating-point exception for INT_MIN % -1, which
* is a bit silly since the correct answer is perfectly well-defined,
* namely zero. (It's not clear this ever happens when dealing with
* int16, but we might as well have the test for safety.)
*/
if (arg2 == -1)
PG_RETURN_INT16(0);
/* No overflow is possible */
PG_RETURN_INT16(arg1 % arg2);
}
| Datum int2mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 830 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
int32 result32;
/*
* The most practical way to detect overflow is to do the arithmetic in
* int32 (so that the result can't overflow) and then do a range check.
*/
result32 = (int32) arg1 *(int32) arg2;
if (result32 < SHRT_MIN || result32 > SHRT_MAX)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16((int16) result32);
}
| Datum int2ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 453 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_BOOL.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 != arg2);
}
| Datum int2not | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1306 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
PG_RETURN_INT16(~arg1);
}
| Datum int2or | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1288 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_INT16(arg1 | arg2);
}
| Datum int2out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 72 of file int.c.
References palloc(), PG_GETARG_INT16, pg_itoa(), and PG_RETURN_CSTRING.
{
int16 arg1 = PG_GETARG_INT16(0);
char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
pg_itoa(arg1, result);
PG_RETURN_CSTRING(result);
}
| Datum int2pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 788 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, and SAMESIGN.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
int16 result;
result = arg1 + arg2;
/*
* Overflow check. If the inputs are of different signs then their sum
* cannot overflow. If the inputs are of the same sign, their sum had
* better be that sign too.
*/
if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16(result);
}
| Datum int2recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 85 of file int.c.
References buf, PG_GETARG_POINTER, PG_RETURN_INT16, and pq_getmsgint().
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_INT16((int16) pq_getmsgint(buf, sizeof(int16)));
}
| Datum int2send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 96 of file int.c.
References buf, PG_GETARG_INT16, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().
{
int16 arg1 = PG_GETARG_INT16(0);
StringInfoData buf;
pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(int16));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
| Datum int2shl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1315 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT16(arg1 << arg2);
}
| Datum int2shr | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1324 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT16(arg1 >> arg2);
}
| Datum int2smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1188 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_INT16((arg1 < arg2) ? arg1 : arg2);
}
| Datum int2um | ( | PG_FUNCTION_ARGS | ) |
Definition at line 765 of file int.c.
References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, and SAMESIGN.
{
int16 arg = PG_GETARG_INT16(0);
int16 result;
result = -arg;
/* overflow check (needed for SHRT_MIN) */
if (arg != 0 && SAMESIGN(result, arg))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("smallint out of range")));
PG_RETURN_INT16(result);
}
| Datum int2up | ( | PG_FUNCTION_ARGS | ) |
Definition at line 780 of file int.c.
References arg, PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg = PG_GETARG_INT16(0);
PG_RETURN_INT16(arg);
}
| Datum int2vectoreq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 262 of file int.c.
References int2vector::dim1, memcmp(), PG_GETARG_POINTER, PG_RETURN_BOOL, and int2vector::values.
{
int2vector *a = (int2vector *) PG_GETARG_POINTER(0);
int2vector *b = (int2vector *) PG_GETARG_POINTER(1);
if (a->dim1 != b->dim1)
PG_RETURN_BOOL(false);
PG_RETURN_BOOL(memcmp(a->values, b->values, a->dim1 * sizeof(int16)) == 0);
}
| Datum int2vectorin | ( | PG_FUNCTION_ARGS | ) |
Definition at line 139 of file int.c.
References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, ereport, errcode(), errmsg(), ERROR, FUNC_MAX_ARGS, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), pg_atoi(), PG_GETARG_CSTRING, PG_RETURN_POINTER, SET_VARSIZE, and int2vector::values.
{
char *intString = PG_GETARG_CSTRING(0);
int2vector *result;
int n;
result = (int2vector *) palloc0(Int2VectorSize(FUNC_MAX_ARGS));
for (n = 0; *intString && n < FUNC_MAX_ARGS; n++)
{
while (*intString && isspace((unsigned char) *intString))
intString++;
if (*intString == '\0')
break;
result->values[n] = pg_atoi(intString, sizeof(int16), ' ');
while (*intString && !isspace((unsigned char) *intString))
intString++;
}
while (*intString && isspace((unsigned char) *intString))
intString++;
if (*intString)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("int2vector has too many elements")));
SET_VARSIZE(result, Int2VectorSize(n));
result->ndim = 1;
result->dataoffset = 0; /* never any nulls */
result->elemtype = INT2OID;
result->dim1 = n;
result->lbound1 = 0;
PG_RETURN_POINTER(result);
}
| Datum int2vectorout | ( | PG_FUNCTION_ARGS | ) |
Definition at line 178 of file int.c.
References int2vector::dim1, palloc(), PG_GETARG_POINTER, pg_itoa(), PG_RETURN_CSTRING, and int2vector::values.
{
int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);
int num,
nnums = int2Array->dim1;
char *rp;
char *result;
/* assumes sign, 5 digits, ' ' */
rp = result = (char *) palloc(nnums * 7 + 1);
for (num = 0; num < nnums; num++)
{
if (num != 0)
*rp++ = ' ';
pg_itoa(int2Array->values[num], rp);
while (*++rp != '\0')
;
}
*rp = '\0';
PG_RETURN_CSTRING(result);
}
| Datum int2vectorrecv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 204 of file int.c.
References FunctionCallInfoData::arg, FunctionCallInfoData::argnull, ARR_DIMS, ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer, ereport, errcode(), errmsg(), ERROR, FunctionCallInfoData::flinfo, FUNC_MAX_ARGS, InitFunctionCallInfoData, INT2OID, Int32GetDatum, InvalidOid, FunctionCallInfoData::isnull, NULL, ObjectIdGetDatum, PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum.
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
FunctionCallInfoData locfcinfo;
int2vector *result;
/*
* Normally one would call array_recv() using DirectFunctionCall3, but
* that does not work since array_recv wants to cache some data using
* fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
* parameter.
*/
InitFunctionCallInfoData(locfcinfo, fcinfo->flinfo, 3,
InvalidOid, NULL, NULL);
locfcinfo.arg[0] = PointerGetDatum(buf);
locfcinfo.arg[1] = ObjectIdGetDatum(INT2OID);
locfcinfo.arg[2] = Int32GetDatum(-1);
locfcinfo.argnull[0] = false;
locfcinfo.argnull[1] = false;
locfcinfo.argnull[2] = false;
result = (int2vector *) DatumGetPointer(array_recv(&locfcinfo));
Assert(!locfcinfo.isnull);
/* sanity checks: int2vector must be 1-D, 0-based, no nulls */
if (ARR_NDIM(result) != 1 ||
ARR_HASNULL(result) ||
ARR_ELEMTYPE(result) != INT2OID ||
ARR_LBOUND(result)[0] != 0)
ereport(ERROR,
(errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
errmsg("invalid int2vector data")));
/* check length for consistency with int2vectorin() */
if (ARR_DIMS(result)[0] > FUNC_MAX_ARGS)
ereport(ERROR,
(errcode(ERRCODE_INVALID_PARAMETER_VALUE),
errmsg("oidvector has too many elements")));
PG_RETURN_POINTER(result);
}
| Datum int2vectorsend | ( | PG_FUNCTION_ARGS | ) |
| Datum int2xor | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1297 of file int.c.
References PG_GETARG_INT16, and PG_RETURN_INT16.
{
int16 arg1 = PG_GETARG_INT16(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_INT16(arg1 ^ arg2);
}
| Datum int42div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1048 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and SAMESIGN.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
int32 result;
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/*
* INT_MIN / -1 is problematic, since the result can't be represented on a
* two's-complement machine. Some machines produce INT_MIN, some produce
* zero, some throw an exception. We can dodge the problem by recognizing
* that division by -1 is the same as negation.
*/
if (arg2 == -1)
{
result = -arg1;
/* overflow check (needed for INT_MIN) */
if (arg1 != 0 && SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
/* No overflow is possible */
result = arg1 / arg2;
PG_RETURN_INT32(result);
}
| Datum int42eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 552 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 == arg2);
}
| Datum int42ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 597 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 >= arg2);
}
| Datum int42gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 588 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 > arg2);
}
| Datum int42le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 579 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 <= arg2);
}
| Datum int42lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 570 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 < arg2);
}
| Datum int42mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1000 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
int32 result;
result = arg1 - arg2;
/*
* Overflow check. If the inputs are of the same sign then their
* difference cannot overflow. If they are of different signs then the
* result should be of the same sign as the first input.
*/
if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int42mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1021 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
int32 result;
result = arg1 * arg2;
/*
* Overflow check. We basically check to see if result / arg1 gives arg2
* again. There is one case where this fails: arg1 = 0 (which cannot
* overflow).
*
* Since the division is likely much more expensive than the actual
* multiplication, we'd like to skip it where possible. The best bang for
* the buck seems to be to check whether both inputs are in the int16
* range; if so, no overflow is possible.
*/
if (!(arg1 >= (int32) SHRT_MIN && arg1 <= (int32) SHRT_MAX) &&
result / arg1 != arg2)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int42ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 561 of file int.c.
References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
PG_RETURN_BOOL(arg1 != arg2);
}
| Datum int42pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 979 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int32 arg1 = PG_GETARG_INT32(0);
int16 arg2 = PG_GETARG_INT16(1);
int32 result;
result = arg1 + arg2;
/*
* Overflow check. If the inputs are of different signs then their sum
* cannot overflow. If the inputs are of the same sign, their sum had
* better be that sign too.
*/
if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4_bool | ( | PG_FUNCTION_ARGS | ) |
Definition at line 356 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
if (PG_GETARG_INT32(0) == 0)
PG_RETURN_BOOL(false);
else
PG_RETURN_BOOL(true);
}
| Datum int4abs | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1149 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 result;
result = (arg1 < 0) ? -arg1 : arg1;
/* overflow check (needed for INT_MIN) */
if (result < 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4and | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1226 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg1 & arg2);
}
| Datum int4div | ( | PG_FUNCTION_ARGS | ) |
Definition at line 709 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and SAMESIGN.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/*
* INT_MIN / -1 is problematic, since the result can't be represented on a
* two's-complement machine. Some machines produce INT_MIN, some produce
* zero, some throw an exception. We can dodge the problem by recognizing
* that division by -1 is the same as negation.
*/
if (arg2 == -1)
{
result = -arg1;
/* overflow check (needed for INT_MIN) */
if (arg1 != 0 && SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
/* No overflow is possible */
result = arg1 / arg2;
PG_RETURN_INT32(result);
}
| Datum int4eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 390 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 == arg2);
}
| Datum int4ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 435 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 >= arg2);
}
| Datum int4gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 426 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 > arg2);
}
| Datum int4in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 281 of file int.c.
References pg_atoi(), PG_GETARG_CSTRING, and PG_RETURN_INT32.
Referenced by funny_dup17(), inet_client_port(), inet_server_port(), and pg_stat_get_backend_client_port().
{
char *num = PG_GETARG_CSTRING(0);
PG_RETURN_INT32(pg_atoi(num, sizeof(int32), '\0'));
}
| Datum int4inc | ( | PG_FUNCTION_ARGS | ) |
Definition at line 749 of file int.c.
References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg = PG_GETARG_INT32(0);
int32 result;
result = arg + 1;
/* Overflow check */
if (arg > 0 && result < 0)
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4larger | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1197 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32((arg1 > arg2) ? arg1 : arg2);
}
| Datum int4le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 417 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 <= arg2);
}
| Datum int4lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 408 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 < arg2);
}
| Datum int4mi | ( | PG_FUNCTION_ARGS | ) |
Definition at line 657 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 - arg2;
/*
* Overflow check. If the inputs are of the same sign then their
* difference cannot overflow. If they are of different signs then the
* result should be of the same sign as the first input.
*/
if (!SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4mod | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1088 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, and PG_RETURN_NULL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
if (arg2 == 0)
{
ereport(ERROR,
(errcode(ERRCODE_DIVISION_BY_ZERO),
errmsg("division by zero")));
/* ensure compiler realizes we mustn't reach the division (gcc bug) */
PG_RETURN_NULL();
}
/*
* Some machines throw a floating-point exception for INT_MIN % -1, which
* is a bit silly since the correct answer is perfectly well-defined,
* namely zero.
*/
if (arg2 == -1)
PG_RETURN_INT32(0);
/* No overflow is possible */
PG_RETURN_INT32(arg1 % arg2);
}
| Datum int4mul | ( | PG_FUNCTION_ARGS | ) |
Definition at line 678 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 * arg2;
/*
* Overflow check. We basically check to see if result / arg2 gives arg1
* again. There are two cases where this fails: arg2 = 0 (which cannot
* overflow) and arg1 = INT_MIN, arg2 = -1 (where the division itself will
* overflow and thus incorrectly match).
*
* Since the division is likely much more expensive than the actual
* multiplication, we'd like to skip it where possible. The best bang for
* the buck seems to be to check whether both inputs are in the int16
* range; if so, no overflow is possible.
*/
if (!(arg1 >= (int32) SHRT_MIN && arg1 <= (int32) SHRT_MAX &&
arg2 >= (int32) SHRT_MIN && arg2 <= (int32) SHRT_MAX) &&
arg2 != 0 &&
((arg2 == -1 && arg1 < 0 && result < 0) ||
result / arg2 != arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 399 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_BOOL.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_BOOL(arg1 != arg2);
}
| Datum int4not | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1271 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
PG_RETURN_INT32(~arg1);
}
| Datum int4or | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1235 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg1 | arg2);
}
| Datum int4out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 292 of file int.c.
References palloc(), PG_GETARG_INT32, pg_ltoa(), and PG_RETURN_CSTRING.
Referenced by int4_to_char().
{
int32 arg1 = PG_GETARG_INT32(0);
char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
pg_ltoa(arg1, result);
PG_RETURN_CSTRING(result);
}
| Datum int4pl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 636 of file int.c.
References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
Referenced by int4range_canonical().
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
int32 result;
result = arg1 + arg2;
/*
* Overflow check. If the inputs are of different signs then their sum
* cannot overflow. If the inputs are of the same sign, their sum had
* better be that sign too.
*/
if (SAMESIGN(arg1, arg2) && !SAMESIGN(result, arg1))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 305 of file int.c.
References buf, PG_GETARG_POINTER, PG_RETURN_INT32, and pq_getmsgint().
{
StringInfo buf = (StringInfo) PG_GETARG_POINTER(0);
PG_RETURN_INT32((int32) pq_getmsgint(buf, sizeof(int32)));
}
| Datum int4send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 316 of file int.c.
References buf, PG_GETARG_INT32, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint().
{
int32 arg1 = PG_GETARG_INT32(0);
StringInfoData buf;
pq_begintypsend(&buf);
pq_sendint(&buf, arg1, sizeof(int32));
PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
}
| Datum int4shl | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1253 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg1 << arg2);
}
| Datum int4shr | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1262 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg1 >> arg2);
}
| Datum int4smaller | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1206 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
}
| Datum int4um | ( | PG_FUNCTION_ARGS | ) |
Definition at line 613 of file int.c.
References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, and SAMESIGN.
{
int32 arg = PG_GETARG_INT32(0);
int32 result;
result = -arg;
/* overflow check (needed for INT_MIN) */
if (arg != 0 && SAMESIGN(result, arg))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("integer out of range")));
PG_RETURN_INT32(result);
}
| Datum int4up | ( | PG_FUNCTION_ARGS | ) |
Definition at line 628 of file int.c.
References arg, PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg = PG_GETARG_INT32(0);
PG_RETURN_INT32(arg);
}
| Datum int4xor | ( | PG_FUNCTION_ARGS | ) |
Definition at line 1244 of file int.c.
References PG_GETARG_INT32, and PG_RETURN_INT32.
{
int32 arg1 = PG_GETARG_INT32(0);
int32 arg2 = PG_GETARG_INT32(1);
PG_RETURN_INT32(arg1 ^ arg2);
}
1.7.1