PostgreSQL Source Code  git master
int.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <math.h>
#include "catalog/pg_type.h"
#include "common/int.h"
#include "funcapi.h"
#include "libpq/pqformat.h"
#include "nodes/nodeFuncs.h"
#include "nodes/supportnodes.h"
#include "optimizer/optimizer.h"
#include "utils/array.h"
#include "utils/builtins.h"
Include dependency graph for int.c:

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Macros

#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)
 
int2vectorbuildint2vector (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 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 in_range_int4_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int4_int8 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int4 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int2 (PG_FUNCTION_ARGS)
 
Datum in_range_int2_int8 (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)
 
static int32 int4gcd_internal (int32 arg1, int32 arg2)
 
Datum int4gcd (PG_FUNCTION_ARGS)
 
Datum int4lcm (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)
 
Datum generate_series_int4_support (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ Int2VectorSize

#define Int2VectorSize (   n)    (offsetof(int2vector, values) + (n) * sizeof(int16))

Definition at line 45 of file int.c.

Function Documentation

◆ bool_int4()

Datum bool_int4 ( PG_FUNCTION_ARGS  )

Definition at line 372 of file int.c.

373 {
374  if (PG_GETARG_BOOL(0) == false)
375  PG_RETURN_INT32(0);
376  else
377  PG_RETURN_INT32(1);
378 }
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274

References PG_GETARG_BOOL, and PG_RETURN_INT32.

◆ buildint2vector()

int2vector* buildint2vector ( const int16 int2s,
int  n 
)

Definition at line 114 of file int.c.

115 {
116  int2vector *result;
117 
118  result = (int2vector *) palloc0(Int2VectorSize(n));
119 
120  if (n > 0 && int2s)
121  memcpy(result->values, int2s, n * sizeof(int16));
122 
123  /*
124  * Attach standard array header. For historical reasons, we set the index
125  * lower bound to 0 not 1.
126  */
127  SET_VARSIZE(result, Int2VectorSize(n));
128  result->ndim = 1;
129  result->dataoffset = 0; /* never any nulls */
130  result->elemtype = INT2OID;
131  result->dim1 = n;
132  result->lbound1 = 0;
133 
134  return result;
135 }
signed short int16
Definition: c.h:493
#define Int2VectorSize(n)
Definition: int.c:45
void * palloc0(Size size)
Definition: mcxt.c:1346
Definition: c.h:715
int ndim
Definition: c.h:717
int dim1
Definition: c.h:720
Oid elemtype
Definition: c.h:719
int16 values[FLEXIBLE_ARRAY_MEMBER]
Definition: c.h:722
int32 dataoffset
Definition: c.h:718
int lbound1
Definition: c.h:721
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), SET_VARSIZE, and int2vector::values.

Referenced by CreateStatistics(), CreateTriggerFiringOn(), pg_get_publication_tables(), publication_add_relation(), StorePartitionKey(), and UpdateIndexRelation().

◆ generate_series_int4()

Datum generate_series_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1503 of file int.c.

1504 {
1505  return generate_series_step_int4(fcinfo);
1506 }
Datum generate_series_step_int4(PG_FUNCTION_ARGS)
Definition: int.c:1509

References generate_series_step_int4().

◆ generate_series_int4_support()

Datum generate_series_int4_support ( PG_FUNCTION_ARGS  )

Definition at line 1585 of file int.c.

1586 {
1587  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1588  Node *ret = NULL;
1589 
1590  if (IsA(rawreq, SupportRequestRows))
1591  {
1592  /* Try to estimate the number of rows returned */
1593  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1594 
1595  if (is_funcclause(req->node)) /* be paranoid */
1596  {
1597  List *args = ((FuncExpr *) req->node)->args;
1598  Node *arg1,
1599  *arg2,
1600  *arg3;
1601 
1602  /* We can use estimated argument values here */
1604  arg2 = estimate_expression_value(req->root, lsecond(args));
1605  if (list_length(args) >= 3)
1606  arg3 = estimate_expression_value(req->root, lthird(args));
1607  else
1608  arg3 = NULL;
1609 
1610  /*
1611  * If any argument is constant NULL, we can safely assume that
1612  * zero rows are returned. Otherwise, if they're all non-NULL
1613  * constants, we can calculate the number of rows that will be
1614  * returned. Use double arithmetic to avoid overflow hazards.
1615  */
1616  if ((IsA(arg1, Const) &&
1617  ((Const *) arg1)->constisnull) ||
1618  (IsA(arg2, Const) &&
1619  ((Const *) arg2)->constisnull) ||
1620  (arg3 != NULL && IsA(arg3, Const) &&
1621  ((Const *) arg3)->constisnull))
1622  {
1623  req->rows = 0;
1624  ret = (Node *) req;
1625  }
1626  else if (IsA(arg1, Const) &&
1627  IsA(arg2, Const) &&
1628  (arg3 == NULL || IsA(arg3, Const)))
1629  {
1630  double start,
1631  finish,
1632  step;
1633 
1634  start = DatumGetInt32(((Const *) arg1)->constvalue);
1635  finish = DatumGetInt32(((Const *) arg2)->constvalue);
1636  step = arg3 ? DatumGetInt32(((Const *) arg3)->constvalue) : 1;
1637 
1638  /* This equation works for either sign of step */
1639  if (step != 0)
1640  {
1641  req->rows = floor((finish - start + step) / step);
1642  ret = (Node *) req;
1643  }
1644  }
1645  }
1646  }
1647 
1648  PG_RETURN_POINTER(ret);
1649 }
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2395
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
return str start
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:67
#define IsA(nodeptr, _type_)
Definition: nodes.h:158
static int list_length(const List *l)
Definition: pg_list.h:152
#define lthird(l)
Definition: pg_list.h:188
#define linitial(l)
Definition: pg_list.h:178
#define lsecond(l)
Definition: pg_list.h:183
static int32 DatumGetInt32(Datum X)
Definition: postgres.h:202
Definition: pg_list.h:54
Definition: nodes.h:129
struct PlannerInfo * root
Definition: supportnodes.h:163

References generate_unaccent_rules::args, DatumGetInt32(), estimate_expression_value(), is_funcclause(), IsA, linitial, list_length(), lsecond, lthird, SupportRequestRows::node, PG_GETARG_POINTER, PG_RETURN_POINTER, SupportRequestRows::root, SupportRequestRows::rows, and start.

◆ generate_series_step_int4()

Datum generate_series_step_int4 ( PG_FUNCTION_ARGS  )

Definition at line 1509 of file int.c.

1510 {
1511  FuncCallContext *funcctx;
1512  generate_series_fctx *fctx;
1513  int32 result;
1514  MemoryContext oldcontext;
1515 
1516  /* stuff done only on the first call of the function */
1517  if (SRF_IS_FIRSTCALL())
1518  {
1520  int32 finish = PG_GETARG_INT32(1);
1521  int32 step = 1;
1522 
1523  /* see if we were given an explicit step size */
1524  if (PG_NARGS() == 3)
1525  step = PG_GETARG_INT32(2);
1526  if (step == 0)
1527  ereport(ERROR,
1528  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1529  errmsg("step size cannot equal zero")));
1530 
1531  /* create a function context for cross-call persistence */
1532  funcctx = SRF_FIRSTCALL_INIT();
1533 
1534  /*
1535  * switch to memory context appropriate for multiple function calls
1536  */
1537  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1538 
1539  /* allocate memory for user context */
1540  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1541 
1542  /*
1543  * Use fctx to keep state from call to call. Seed current with the
1544  * original start value
1545  */
1546  fctx->current = start;
1547  fctx->finish = finish;
1548  fctx->step = step;
1549 
1550  funcctx->user_fctx = fctx;
1551  MemoryContextSwitchTo(oldcontext);
1552  }
1553 
1554  /* stuff done on every call of the function */
1555  funcctx = SRF_PERCALL_SETUP();
1556 
1557  /*
1558  * get the saved state and use current as the result for this iteration
1559  */
1560  fctx = funcctx->user_fctx;
1561  result = fctx->current;
1562 
1563  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1564  (fctx->step < 0 && fctx->current >= fctx->finish))
1565  {
1566  /*
1567  * Increment current in preparation for next iteration. If next-value
1568  * computation overflows, this is the final result.
1569  */
1570  if (pg_add_s32_overflow(fctx->current, fctx->step, &fctx->current))
1571  fctx->step = 0;
1572 
1573  /* do when there is more left to send */
1574  SRF_RETURN_NEXT(funcctx, Int32GetDatum(result));
1575  }
1576  else
1577  /* do when there is no more left */
1578  SRF_RETURN_DONE(funcctx);
1579 }
signed int int32
Definition: c.h:494
int errcode(int sqlerrcode)
Definition: elog.c:859
int errmsg(const char *fmt,...)
Definition: elog.c:1072
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_NARGS()
Definition: fmgr.h:203
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:304
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:308
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:310
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:306
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:328
static bool pg_add_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:104
void * palloc(Size size)
Definition: mcxt.c:1316
static Datum Int32GetDatum(int32 X)
Definition: postgres.h:212
MemoryContextSwitchTo(old_ctx)
void * user_fctx
Definition: funcapi.h:82
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:101
int32 current
Definition: int.c:49
int32 finish
Definition: int.c:50

References generate_series_fctx::current, ereport, errcode(), errmsg(), ERROR, generate_series_fctx::finish, Int32GetDatum(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), pg_add_s32_overflow(), PG_GETARG_INT32, PG_NARGS, SRF_FIRSTCALL_INIT, SRF_IS_FIRSTCALL, SRF_PERCALL_SETUP, SRF_RETURN_DONE, SRF_RETURN_NEXT, start, generate_series_fctx::step, and FuncCallContext::user_fctx.

Referenced by generate_series_int4().

◆ i2toi4()

Datum i2toi4 ( PG_FUNCTION_ARGS  )

Definition at line 340 of file int.c.

341 {
342  int16 arg1 = PG_GETARG_INT16(0);
343 
344  PG_RETURN_INT32((int32) arg1);
345 }
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

References PG_GETARG_INT16, and PG_RETURN_INT32.

◆ i4toi2()

Datum i4toi2 ( PG_FUNCTION_ARGS  )

Definition at line 348 of file int.c.

349 {
350  int32 arg1 = PG_GETARG_INT32(0);
351 
352  if (unlikely(arg1 < SHRT_MIN) || unlikely(arg1 > SHRT_MAX))
353  ereport(ERROR,
354  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
355  errmsg("smallint out of range")));
356 
357  PG_RETURN_INT16((int16) arg1);
358 }
#define unlikely(x)
Definition: c.h:311
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT16, and unlikely.

◆ in_range_int2_int2()

Datum in_range_int2_int2 ( PG_FUNCTION_ARGS  )

Definition at line 739 of file int.c.

740 {
741  /* Doesn't seem worth duplicating code for, so just invoke int2_int4 */
743  PG_GETARG_DATUM(0),
744  PG_GETARG_DATUM(1),
746  PG_GETARG_DATUM(3),
747  PG_GETARG_DATUM(4));
748 }
#define PG_GETARG_DATUM(n)
Definition: fmgr.h:268
#define DirectFunctionCall5(func, arg1, arg2, arg3, arg4, arg5)
Definition: fmgr.h:650
Datum in_range_int2_int4(PG_FUNCTION_ARGS)
Definition: int.c:704

References DirectFunctionCall5, in_range_int2_int4(), Int32GetDatum(), PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int2_int4()

Datum in_range_int2_int4 ( PG_FUNCTION_ARGS  )

Definition at line 704 of file int.c.

705 {
706  /* We must do all the math in int32 */
708  int32 base = (int32) PG_GETARG_INT16(1);
709  int32 offset = PG_GETARG_INT32(2);
710  bool sub = PG_GETARG_BOOL(3);
711  bool less = PG_GETARG_BOOL(4);
712  int32 sum;
713 
714  if (offset < 0)
715  ereport(ERROR,
716  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
717  errmsg("invalid preceding or following size in window function")));
718 
719  if (sub)
720  offset = -offset; /* cannot overflow */
721 
722  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
723  {
724  /*
725  * If sub is false, the true sum is surely more than val, so correct
726  * answer is the same as "less". If sub is true, the true sum is
727  * surely less than val, so the answer is "!less".
728  */
729  PG_RETURN_BOOL(sub ? !less : less);
730  }
731 
732  if (less)
733  PG_RETURN_BOOL(val <= sum);
734  else
735  PG_RETURN_BOOL(val >= sum);
736 }
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
long val
Definition: informix.c:670

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int2().

◆ in_range_int2_int8()

Datum in_range_int2_int8 ( PG_FUNCTION_ARGS  )

Definition at line 751 of file int.c.

752 {
753  /* Doesn't seem worth duplicating code for, so just invoke int4_int8 */
757  PG_GETARG_DATUM(2),
758  PG_GETARG_DATUM(3),
759  PG_GETARG_DATUM(4));
760 }
Datum in_range_int4_int8(PG_FUNCTION_ARGS)
Definition: int.c:669

References DirectFunctionCall5, in_range_int4_int8(), Int32GetDatum(), PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int4_int2()

Datum in_range_int4_int2 ( PG_FUNCTION_ARGS  )

Definition at line 657 of file int.c.

658 {
659  /* Doesn't seem worth duplicating code for, so just invoke int4_int4 */
661  PG_GETARG_DATUM(0),
662  PG_GETARG_DATUM(1),
664  PG_GETARG_DATUM(3),
665  PG_GETARG_DATUM(4));
666 }
Datum in_range_int4_int4(PG_FUNCTION_ARGS)
Definition: int.c:623

References DirectFunctionCall5, in_range_int4_int4(), Int32GetDatum(), PG_GETARG_DATUM, and PG_GETARG_INT16.

◆ in_range_int4_int4()

Datum in_range_int4_int4 ( PG_FUNCTION_ARGS  )

Definition at line 623 of file int.c.

624 {
626  int32 base = PG_GETARG_INT32(1);
627  int32 offset = PG_GETARG_INT32(2);
628  bool sub = PG_GETARG_BOOL(3);
629  bool less = PG_GETARG_BOOL(4);
630  int32 sum;
631 
632  if (offset < 0)
633  ereport(ERROR,
634  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
635  errmsg("invalid preceding or following size in window function")));
636 
637  if (sub)
638  offset = -offset; /* cannot overflow */
639 
640  if (unlikely(pg_add_s32_overflow(base, offset, &sum)))
641  {
642  /*
643  * If sub is false, the true sum is surely more than val, so correct
644  * answer is the same as "less". If sub is true, the true sum is
645  * surely less than val, so the answer is "!less".
646  */
647  PG_RETURN_BOOL(sub ? !less : less);
648  }
649 
650  if (less)
651  PG_RETURN_BOOL(val <= sum);
652  else
653  PG_RETURN_BOOL(val >= sum);
654 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int4_int2().

◆ in_range_int4_int8()

Datum in_range_int4_int8 ( PG_FUNCTION_ARGS  )

Definition at line 669 of file int.c.

670 {
671  /* We must do all the math in int64 */
672  int64 val = (int64) PG_GETARG_INT32(0);
673  int64 base = (int64) PG_GETARG_INT32(1);
674  int64 offset = PG_GETARG_INT64(2);
675  bool sub = PG_GETARG_BOOL(3);
676  bool less = PG_GETARG_BOOL(4);
677  int64 sum;
678 
679  if (offset < 0)
680  ereport(ERROR,
681  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
682  errmsg("invalid preceding or following size in window function")));
683 
684  if (sub)
685  offset = -offset; /* cannot overflow */
686 
687  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
688  {
689  /*
690  * If sub is false, the true sum is surely more than val, so correct
691  * answer is the same as "less". If sub is true, the true sum is
692  * surely less than val, so the answer is "!less".
693  */
694  PG_RETURN_BOOL(sub ? !less : less);
695  }
696 
697  if (less)
698  PG_RETURN_BOOL(val <= sum);
699  else
700  PG_RETURN_BOOL(val >= sum);
701 }
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_BOOL, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_BOOL, unlikely, and val.

Referenced by in_range_int2_int8().

◆ int24div()

Datum int24div ( PG_FUNCTION_ARGS  )

Definition at line 1030 of file int.c.

1031 {
1032  int16 arg1 = PG_GETARG_INT16(0);
1033  int32 arg2 = PG_GETARG_INT32(1);
1034 
1035  if (unlikely(arg2 == 0))
1036  {
1037  ereport(ERROR,
1038  (errcode(ERRCODE_DIVISION_BY_ZERO),
1039  errmsg("division by zero")));
1040  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1041  PG_RETURN_NULL();
1042  }
1043 
1044  /* No overflow is possible */
1045  PG_RETURN_INT32((int32) arg1 / arg2);
1046 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int24eq()

Datum int24eq ( PG_FUNCTION_ARGS  )

Definition at line 504 of file int.c.

505 {
506  int16 arg1 = PG_GETARG_INT16(0);
507  int32 arg2 = PG_GETARG_INT32(1);
508 
509  PG_RETURN_BOOL(arg1 == arg2);
510 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24ge()

Datum int24ge ( PG_FUNCTION_ARGS  )

Definition at line 549 of file int.c.

550 {
551  int16 arg1 = PG_GETARG_INT16(0);
552  int32 arg2 = PG_GETARG_INT32(1);
553 
554  PG_RETURN_BOOL(arg1 >= arg2);
555 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24gt()

Datum int24gt ( PG_FUNCTION_ARGS  )

Definition at line 540 of file int.c.

541 {
542  int16 arg1 = PG_GETARG_INT16(0);
543  int32 arg2 = PG_GETARG_INT32(1);
544 
545  PG_RETURN_BOOL(arg1 > arg2);
546 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24le()

Datum int24le ( PG_FUNCTION_ARGS  )

Definition at line 531 of file int.c.

532 {
533  int16 arg1 = PG_GETARG_INT16(0);
534  int32 arg2 = PG_GETARG_INT32(1);
535 
536  PG_RETURN_BOOL(arg1 <= arg2);
537 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24lt()

Datum int24lt ( PG_FUNCTION_ARGS  )

Definition at line 522 of file int.c.

523 {
524  int16 arg1 = PG_GETARG_INT16(0);
525  int32 arg2 = PG_GETARG_INT32(1);
526 
527  PG_RETURN_BOOL(arg1 < arg2);
528 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24mi()

Datum int24mi ( PG_FUNCTION_ARGS  )

Definition at line 1002 of file int.c.

1003 {
1004  int16 arg1 = PG_GETARG_INT16(0);
1005  int32 arg2 = PG_GETARG_INT32(1);
1006  int32 result;
1007 
1008  if (unlikely(pg_sub_s32_overflow((int32) arg1, arg2, &result)))
1009  ereport(ERROR,
1010  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1011  errmsg("integer out of range")));
1012  PG_RETURN_INT32(result);
1013 }
static bool pg_sub_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:122

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int24mul()

Datum int24mul ( PG_FUNCTION_ARGS  )

Definition at line 1016 of file int.c.

1017 {
1018  int16 arg1 = PG_GETARG_INT16(0);
1019  int32 arg2 = PG_GETARG_INT32(1);
1020  int32 result;
1021 
1022  if (unlikely(pg_mul_s32_overflow((int32) arg1, arg2, &result)))
1023  ereport(ERROR,
1024  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1025  errmsg("integer out of range")));
1026  PG_RETURN_INT32(result);
1027 }
static bool pg_mul_s32_overflow(int32 a, int32 b, int32 *result)
Definition: int.h:140

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int24ne()

Datum int24ne ( PG_FUNCTION_ARGS  )

Definition at line 513 of file int.c.

514 {
515  int16 arg1 = PG_GETARG_INT16(0);
516  int32 arg2 = PG_GETARG_INT32(1);
517 
518  PG_RETURN_BOOL(arg1 != arg2);
519 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int24pl()

Datum int24pl ( PG_FUNCTION_ARGS  )

Definition at line 988 of file int.c.

989 {
990  int16 arg1 = PG_GETARG_INT16(0);
991  int32 arg2 = PG_GETARG_INT32(1);
992  int32 result;
993 
994  if (unlikely(pg_add_s32_overflow((int32) arg1, arg2, &result)))
995  ereport(ERROR,
996  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
997  errmsg("integer out of range")));
998  PG_RETURN_INT32(result);
999 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int2abs()

Datum int2abs ( PG_FUNCTION_ARGS  )

Definition at line 1205 of file int.c.

1206 {
1207  int16 arg1 = PG_GETARG_INT16(0);
1208  int16 result;
1209 
1210  if (unlikely(arg1 == PG_INT16_MIN))
1211  ereport(ERROR,
1212  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1213  errmsg("smallint out of range")));
1214  result = (arg1 < 0) ? -arg1 : arg1;
1215  PG_RETURN_INT16(result);
1216 }
#define PG_INT16_MIN
Definition: c.h:585

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

◆ int2and()

Datum int2and ( PG_FUNCTION_ARGS  )

Definition at line 1446 of file int.c.

1447 {
1448  int16 arg1 = PG_GETARG_INT16(0);
1449  int16 arg2 = PG_GETARG_INT16(1);
1450 
1451  PG_RETURN_INT16(arg1 & arg2);
1452 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2div()

Datum int2div ( PG_FUNCTION_ARGS  )

Definition at line 949 of file int.c.

950 {
951  int16 arg1 = PG_GETARG_INT16(0);
952  int16 arg2 = PG_GETARG_INT16(1);
953  int16 result;
954 
955  if (arg2 == 0)
956  {
957  ereport(ERROR,
958  (errcode(ERRCODE_DIVISION_BY_ZERO),
959  errmsg("division by zero")));
960  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
961  PG_RETURN_NULL();
962  }
963 
964  /*
965  * SHRT_MIN / -1 is problematic, since the result can't be represented on
966  * a two's-complement machine. Some machines produce SHRT_MIN, some
967  * produce zero, some throw an exception. We can dodge the problem by
968  * recognizing that division by -1 is the same as negation.
969  */
970  if (arg2 == -1)
971  {
972  if (unlikely(arg1 == PG_INT16_MIN))
973  ereport(ERROR,
974  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
975  errmsg("smallint out of range")));
976  result = -arg1;
977  PG_RETURN_INT16(result);
978  }
979 
980  /* No overflow is possible */
981 
982  result = arg1 / arg2;
983 
984  PG_RETURN_INT16(result);
985 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

◆ int2eq()

Datum int2eq ( PG_FUNCTION_ARGS  )

Definition at line 450 of file int.c.

451 {
452  int16 arg1 = PG_GETARG_INT16(0);
453  int16 arg2 = PG_GETARG_INT16(1);
454 
455  PG_RETURN_BOOL(arg1 == arg2);
456 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2ge()

Datum int2ge ( PG_FUNCTION_ARGS  )

Definition at line 495 of file int.c.

496 {
497  int16 arg1 = PG_GETARG_INT16(0);
498  int16 arg2 = PG_GETARG_INT16(1);
499 
500  PG_RETURN_BOOL(arg1 >= arg2);
501 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2gt()

Datum int2gt ( PG_FUNCTION_ARGS  )

Definition at line 486 of file int.c.

487 {
488  int16 arg1 = PG_GETARG_INT16(0);
489  int16 arg2 = PG_GETARG_INT16(1);
490 
491  PG_RETURN_BOOL(arg1 > arg2);
492 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2in()

Datum int2in ( PG_FUNCTION_ARGS  )

Definition at line 63 of file int.c.

64 {
65  char *num = PG_GETARG_CSTRING(0);
66 
67  PG_RETURN_INT16(pg_strtoint16_safe(num, fcinfo->context));
68 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
int16 pg_strtoint16_safe(const char *s, Node *escontext)
Definition: numutils.c:127

References PG_GETARG_CSTRING, PG_RETURN_INT16, and pg_strtoint16_safe().

◆ int2larger()

Datum int2larger ( PG_FUNCTION_ARGS  )

Definition at line 1346 of file int.c.

1347 {
1348  int16 arg1 = PG_GETARG_INT16(0);
1349  int16 arg2 = PG_GETARG_INT16(1);
1350 
1351  PG_RETURN_INT16((arg1 > arg2) ? arg1 : arg2);
1352 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2le()

Datum int2le ( PG_FUNCTION_ARGS  )

Definition at line 477 of file int.c.

478 {
479  int16 arg1 = PG_GETARG_INT16(0);
480  int16 arg2 = PG_GETARG_INT16(1);
481 
482  PG_RETURN_BOOL(arg1 <= arg2);
483 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2lt()

Datum int2lt ( PG_FUNCTION_ARGS  )

Definition at line 468 of file int.c.

469 {
470  int16 arg1 = PG_GETARG_INT16(0);
471  int16 arg2 = PG_GETARG_INT16(1);
472 
473  PG_RETURN_BOOL(arg1 < arg2);
474 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2mi()

Datum int2mi ( PG_FUNCTION_ARGS  )

Definition at line 920 of file int.c.

921 {
922  int16 arg1 = PG_GETARG_INT16(0);
923  int16 arg2 = PG_GETARG_INT16(1);
924  int16 result;
925 
926  if (unlikely(pg_sub_s16_overflow(arg1, arg2, &result)))
927  ereport(ERROR,
928  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
929  errmsg("smallint out of range")));
930  PG_RETURN_INT16(result);
931 }
static bool pg_sub_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:65

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, pg_sub_s16_overflow(), and unlikely.

◆ int2mod()

Datum int2mod ( PG_FUNCTION_ARGS  )

Definition at line 1158 of file int.c.

1159 {
1160  int16 arg1 = PG_GETARG_INT16(0);
1161  int16 arg2 = PG_GETARG_INT16(1);
1162 
1163  if (unlikely(arg2 == 0))
1164  {
1165  ereport(ERROR,
1166  (errcode(ERRCODE_DIVISION_BY_ZERO),
1167  errmsg("division by zero")));
1168  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1169  PG_RETURN_NULL();
1170  }
1171 
1172  /*
1173  * Some machines throw a floating-point exception for INT_MIN % -1, which
1174  * is a bit silly since the correct answer is perfectly well-defined,
1175  * namely zero. (It's not clear this ever happens when dealing with
1176  * int16, but we might as well have the test for safety.)
1177  */
1178  if (arg2 == -1)
1179  PG_RETURN_INT16(0);
1180 
1181  /* No overflow is possible */
1182 
1183  PG_RETURN_INT16(arg1 % arg2);
1184 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_RETURN_INT16, PG_RETURN_NULL, and unlikely.

◆ int2mul()

Datum int2mul ( PG_FUNCTION_ARGS  )

Definition at line 934 of file int.c.

935 {
936  int16 arg1 = PG_GETARG_INT16(0);
937  int16 arg2 = PG_GETARG_INT16(1);
938  int16 result;
939 
940  if (unlikely(pg_mul_s16_overflow(arg1, arg2, &result)))
941  ereport(ERROR,
942  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
943  errmsg("smallint out of range")));
944 
945  PG_RETURN_INT16(result);
946 }
static bool pg_mul_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:83

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, pg_mul_s16_overflow(), PG_RETURN_INT16, and unlikely.

◆ int2ne()

Datum int2ne ( PG_FUNCTION_ARGS  )

Definition at line 459 of file int.c.

460 {
461  int16 arg1 = PG_GETARG_INT16(0);
462  int16 arg2 = PG_GETARG_INT16(1);
463 
464  PG_RETURN_BOOL(arg1 != arg2);
465 }

References PG_GETARG_INT16, and PG_RETURN_BOOL.

◆ int2not()

Datum int2not ( PG_FUNCTION_ARGS  )

Definition at line 1473 of file int.c.

1474 {
1475  int16 arg1 = PG_GETARG_INT16(0);
1476 
1477  PG_RETURN_INT16(~arg1);
1478 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2or()

Datum int2or ( PG_FUNCTION_ARGS  )

Definition at line 1455 of file int.c.

1456 {
1457  int16 arg1 = PG_GETARG_INT16(0);
1458  int16 arg2 = PG_GETARG_INT16(1);
1459 
1460  PG_RETURN_INT16(arg1 | arg2);
1461 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2out()

Datum int2out ( PG_FUNCTION_ARGS  )

Definition at line 74 of file int.c.

75 {
76  int16 arg1 = PG_GETARG_INT16(0);
77  char *result = (char *) palloc(7); /* sign, 5 digits, '\0' */
78 
79  pg_itoa(arg1, result);
80  PG_RETURN_CSTRING(result);
81 }
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
int pg_itoa(int16 i, char *a)
Definition: numutils.c:1044

References palloc(), PG_GETARG_INT16, pg_itoa(), and PG_RETURN_CSTRING.

◆ int2pl()

Datum int2pl ( PG_FUNCTION_ARGS  )

Definition at line 906 of file int.c.

907 {
908  int16 arg1 = PG_GETARG_INT16(0);
909  int16 arg2 = PG_GETARG_INT16(1);
910  int16 result;
911 
912  if (unlikely(pg_add_s16_overflow(arg1, arg2, &result)))
913  ereport(ERROR,
914  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
915  errmsg("smallint out of range")));
916  PG_RETURN_INT16(result);
917 }
static bool pg_add_s16_overflow(int16 a, int16 b, int16 *result)
Definition: int.h:47

References ereport, errcode(), errmsg(), ERROR, pg_add_s16_overflow(), PG_GETARG_INT16, PG_RETURN_INT16, and unlikely.

◆ int2recv()

Datum int2recv ( PG_FUNCTION_ARGS  )

Definition at line 87 of file int.c.

88 {
90 
92 }
static char * buf
Definition: pg_test_fsync.c:73
unsigned int pq_getmsgint(StringInfo msg, int b)
Definition: pqformat.c:415
StringInfoData * StringInfo
Definition: stringinfo.h:54

References buf, PG_GETARG_POINTER, PG_RETURN_INT16, and pq_getmsgint().

◆ int2send()

Datum int2send ( PG_FUNCTION_ARGS  )

Definition at line 98 of file int.c.

99 {
100  int16 arg1 = PG_GETARG_INT16(0);
102 
104  pq_sendint16(&buf, arg1);
106 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:326
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:346
static void pq_sendint16(StringInfo buf, uint16 i)
Definition: pqformat.h:136

References buf, PG_GETARG_INT16, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint16().

◆ int2shl()

Datum int2shl ( PG_FUNCTION_ARGS  )

Definition at line 1482 of file int.c.

1483 {
1484  int16 arg1 = PG_GETARG_INT16(0);
1485  int32 arg2 = PG_GETARG_INT32(1);
1486 
1487  PG_RETURN_INT16(arg1 << arg2);
1488 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

◆ int2shr()

Datum int2shr ( PG_FUNCTION_ARGS  )

Definition at line 1491 of file int.c.

1492 {
1493  int16 arg1 = PG_GETARG_INT16(0);
1494  int32 arg2 = PG_GETARG_INT32(1);
1495 
1496  PG_RETURN_INT16(arg1 >> arg2);
1497 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_INT16.

◆ int2smaller()

Datum int2smaller ( PG_FUNCTION_ARGS  )

Definition at line 1355 of file int.c.

1356 {
1357  int16 arg1 = PG_GETARG_INT16(0);
1358  int16 arg2 = PG_GETARG_INT16(1);
1359 
1360  PG_RETURN_INT16((arg1 < arg2) ? arg1 : arg2);
1361 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2um()

Datum int2um ( PG_FUNCTION_ARGS  )

Definition at line 886 of file int.c.

887 {
889 
890  if (unlikely(arg == PG_INT16_MIN))
891  ereport(ERROR,
892  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
893  errmsg("smallint out of range")));
895 }
void * arg

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_INT16_MIN, PG_RETURN_INT16, and unlikely.

◆ int2up()

Datum int2up ( PG_FUNCTION_ARGS  )

Definition at line 898 of file int.c.

899 {
901 
903 }

References arg, PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int2vectorin()

Datum int2vectorin ( PG_FUNCTION_ARGS  )

Definition at line 141 of file int.c.

142 {
143  char *intString = PG_GETARG_CSTRING(0);
144  Node *escontext = fcinfo->context;
145  int2vector *result;
146  int nalloc;
147  int n;
148 
149  nalloc = 32; /* arbitrary initial size guess */
150  result = (int2vector *) palloc0(Int2VectorSize(nalloc));
151 
152  for (n = 0;; n++)
153  {
154  long l;
155  char *endp;
156 
157  while (*intString && isspace((unsigned char) *intString))
158  intString++;
159  if (*intString == '\0')
160  break;
161 
162  if (n >= nalloc)
163  {
164  nalloc *= 2;
165  result = (int2vector *) repalloc(result, Int2VectorSize(nalloc));
166  }
167 
168  errno = 0;
169  l = strtol(intString, &endp, 10);
170 
171  if (intString == endp)
172  ereturn(escontext, (Datum) 0,
173  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
174  errmsg("invalid input syntax for type %s: \"%s\"",
175  "smallint", intString)));
176 
177  if (errno == ERANGE || l < SHRT_MIN || l > SHRT_MAX)
178  ereturn(escontext, (Datum) 0,
179  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
180  errmsg("value \"%s\" is out of range for type %s", intString,
181  "smallint")));
182 
183  if (*endp && *endp != ' ')
184  ereturn(escontext, (Datum) 0,
185  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
186  errmsg("invalid input syntax for type %s: \"%s\"",
187  "smallint", intString)));
188 
189  result->values[n] = l;
190  intString = endp;
191  }
192 
193  SET_VARSIZE(result, Int2VectorSize(n));
194  result->ndim = 1;
195  result->dataoffset = 0; /* never any nulls */
196  result->elemtype = INT2OID;
197  result->dim1 = n;
198  result->lbound1 = 0;
199 
200  PG_RETURN_POINTER(result);
201 }
#define ereturn(context, dummy_value,...)
Definition: elog.h:276
void * repalloc(void *pointer, Size size)
Definition: mcxt.c:1540
uintptr_t Datum
Definition: postgres.h:64

References int2vector::dataoffset, int2vector::dim1, int2vector::elemtype, ereturn, errcode(), errmsg(), Int2VectorSize, int2vector::lbound1, int2vector::ndim, palloc0(), PG_GETARG_CSTRING, PG_RETURN_POINTER, repalloc(), SET_VARSIZE, and int2vector::values.

◆ int2vectorout()

Datum int2vectorout ( PG_FUNCTION_ARGS  )

Definition at line 207 of file int.c.

208 {
209  int2vector *int2Array = (int2vector *) PG_GETARG_POINTER(0);
210  int num,
211  nnums = int2Array->dim1;
212  char *rp;
213  char *result;
214 
215  /* assumes sign, 5 digits, ' ' */
216  rp = result = (char *) palloc(nnums * 7 + 1);
217  for (num = 0; num < nnums; num++)
218  {
219  if (num != 0)
220  *rp++ = ' ';
221  rp += pg_itoa(int2Array->values[num], rp);
222  }
223  *rp = '\0';
224  PG_RETURN_CSTRING(result);
225 }

References int2vector::dim1, palloc(), PG_GETARG_POINTER, pg_itoa(), PG_RETURN_CSTRING, and int2vector::values.

◆ int2vectorrecv()

Datum int2vectorrecv ( PG_FUNCTION_ARGS  )

Definition at line 231 of file int.c.

232 {
233  LOCAL_FCINFO(locfcinfo, 3);
235  int2vector *result;
236 
237  /*
238  * Normally one would call array_recv() using DirectFunctionCall3, but
239  * that does not work since array_recv wants to cache some data using
240  * fcinfo->flinfo->fn_extra. So we need to pass it our own flinfo
241  * parameter.
242  */
243  InitFunctionCallInfoData(*locfcinfo, fcinfo->flinfo, 3,
244  InvalidOid, NULL, NULL);
245 
246  locfcinfo->args[0].value = PointerGetDatum(buf);
247  locfcinfo->args[0].isnull = false;
248  locfcinfo->args[1].value = ObjectIdGetDatum(INT2OID);
249  locfcinfo->args[1].isnull = false;
250  locfcinfo->args[2].value = Int32GetDatum(-1);
251  locfcinfo->args[2].isnull = false;
252 
253  result = (int2vector *) DatumGetPointer(array_recv(locfcinfo));
254 
255  Assert(!locfcinfo->isnull);
256 
257  /* sanity checks: int2vector must be 1-D, 0-based, no nulls */
258  if (ARR_NDIM(result) != 1 ||
259  ARR_HASNULL(result) ||
260  ARR_ELEMTYPE(result) != INT2OID ||
261  ARR_LBOUND(result)[0] != 0)
262  ereport(ERROR,
263  (errcode(ERRCODE_INVALID_BINARY_REPRESENTATION),
264  errmsg("invalid int2vector data")));
265 
266  PG_RETURN_POINTER(result);
267 }
#define ARR_NDIM(a)
Definition: array.h:290
#define ARR_ELEMTYPE(a)
Definition: array.h:292
#define ARR_HASNULL(a)
Definition: array.h:291
#define ARR_LBOUND(a)
Definition: array.h:296
Datum array_recv(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1271
#define Assert(condition)
Definition: c.h:858
#define InitFunctionCallInfoData(Fcinfo, Flinfo, Nargs, Collation, Context, Resultinfo)
Definition: fmgr.h:150
#define LOCAL_FCINFO(name, nargs)
Definition: fmgr.h:110
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:322
static Datum ObjectIdGetDatum(Oid X)
Definition: postgres.h:252
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:312
#define InvalidOid
Definition: postgres_ext.h:36

References ARR_ELEMTYPE, ARR_HASNULL, ARR_LBOUND, ARR_NDIM, array_recv(), Assert, buf, DatumGetPointer(), ereport, errcode(), errmsg(), ERROR, InitFunctionCallInfoData, Int32GetDatum(), InvalidOid, LOCAL_FCINFO, ObjectIdGetDatum(), PG_GETARG_POINTER, PG_RETURN_POINTER, and PointerGetDatum().

◆ int2vectorsend()

Datum int2vectorsend ( PG_FUNCTION_ARGS  )

Definition at line 273 of file int.c.

274 {
275  return array_send(fcinfo);
276 }
Datum array_send(PG_FUNCTION_ARGS)
Definition: arrayfuncs.c:1548

References array_send().

◆ int2xor()

Datum int2xor ( PG_FUNCTION_ARGS  )

Definition at line 1464 of file int.c.

1465 {
1466  int16 arg1 = PG_GETARG_INT16(0);
1467  int16 arg2 = PG_GETARG_INT16(1);
1468 
1469  PG_RETURN_INT16(arg1 ^ arg2);
1470 }

References PG_GETARG_INT16, and PG_RETURN_INT16.

◆ int42div()

Datum int42div ( PG_FUNCTION_ARGS  )

Definition at line 1091 of file int.c.

1092 {
1093  int32 arg1 = PG_GETARG_INT32(0);
1094  int16 arg2 = PG_GETARG_INT16(1);
1095  int32 result;
1096 
1097  if (unlikely(arg2 == 0))
1098  {
1099  ereport(ERROR,
1100  (errcode(ERRCODE_DIVISION_BY_ZERO),
1101  errmsg("division by zero")));
1102  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1103  PG_RETURN_NULL();
1104  }
1105 
1106  /*
1107  * INT_MIN / -1 is problematic, since the result can't be represented on a
1108  * two's-complement machine. Some machines produce INT_MIN, some produce
1109  * zero, some throw an exception. We can dodge the problem by recognizing
1110  * that division by -1 is the same as negation.
1111  */
1112  if (arg2 == -1)
1113  {
1114  if (unlikely(arg1 == PG_INT32_MIN))
1115  ereport(ERROR,
1116  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1117  errmsg("integer out of range")));
1118  result = -arg1;
1119  PG_RETURN_INT32(result);
1120  }
1121 
1122  /* No overflow is possible */
1123 
1124  result = arg1 / arg2;
1125 
1126  PG_RETURN_INT32(result);
1127 }
#define PG_INT32_MIN
Definition: c.h:588

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int42eq()

Datum int42eq ( PG_FUNCTION_ARGS  )

Definition at line 558 of file int.c.

559 {
560  int32 arg1 = PG_GETARG_INT32(0);
561  int16 arg2 = PG_GETARG_INT16(1);
562 
563  PG_RETURN_BOOL(arg1 == arg2);
564 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42ge()

Datum int42ge ( PG_FUNCTION_ARGS  )

Definition at line 603 of file int.c.

604 {
605  int32 arg1 = PG_GETARG_INT32(0);
606  int16 arg2 = PG_GETARG_INT16(1);
607 
608  PG_RETURN_BOOL(arg1 >= arg2);
609 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42gt()

Datum int42gt ( PG_FUNCTION_ARGS  )

Definition at line 594 of file int.c.

595 {
596  int32 arg1 = PG_GETARG_INT32(0);
597  int16 arg2 = PG_GETARG_INT16(1);
598 
599  PG_RETURN_BOOL(arg1 > arg2);
600 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42le()

Datum int42le ( PG_FUNCTION_ARGS  )

Definition at line 585 of file int.c.

586 {
587  int32 arg1 = PG_GETARG_INT32(0);
588  int16 arg2 = PG_GETARG_INT16(1);
589 
590  PG_RETURN_BOOL(arg1 <= arg2);
591 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42lt()

Datum int42lt ( PG_FUNCTION_ARGS  )

Definition at line 576 of file int.c.

577 {
578  int32 arg1 = PG_GETARG_INT32(0);
579  int16 arg2 = PG_GETARG_INT16(1);
580 
581  PG_RETURN_BOOL(arg1 < arg2);
582 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42mi()

Datum int42mi ( PG_FUNCTION_ARGS  )

Definition at line 1063 of file int.c.

1064 {
1065  int32 arg1 = PG_GETARG_INT32(0);
1066  int16 arg2 = PG_GETARG_INT16(1);
1067  int32 result;
1068 
1069  if (unlikely(pg_sub_s32_overflow(arg1, (int32) arg2, &result)))
1070  ereport(ERROR,
1071  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1072  errmsg("integer out of range")));
1073  PG_RETURN_INT32(result);
1074 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int42mul()

Datum int42mul ( PG_FUNCTION_ARGS  )

Definition at line 1077 of file int.c.

1078 {
1079  int32 arg1 = PG_GETARG_INT32(0);
1080  int16 arg2 = PG_GETARG_INT16(1);
1081  int32 result;
1082 
1083  if (unlikely(pg_mul_s32_overflow(arg1, (int32) arg2, &result)))
1084  ereport(ERROR,
1085  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1086  errmsg("integer out of range")));
1087  PG_RETURN_INT32(result);
1088 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int42ne()

Datum int42ne ( PG_FUNCTION_ARGS  )

Definition at line 567 of file int.c.

568 {
569  int32 arg1 = PG_GETARG_INT32(0);
570  int16 arg2 = PG_GETARG_INT16(1);
571 
572  PG_RETURN_BOOL(arg1 != arg2);
573 }

References PG_GETARG_INT16, PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int42pl()

Datum int42pl ( PG_FUNCTION_ARGS  )

Definition at line 1049 of file int.c.

1050 {
1051  int32 arg1 = PG_GETARG_INT32(0);
1052  int16 arg2 = PG_GETARG_INT16(1);
1053  int32 result;
1054 
1055  if (unlikely(pg_add_s32_overflow(arg1, (int32) arg2, &result)))
1056  ereport(ERROR,
1057  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1058  errmsg("integer out of range")));
1059  PG_RETURN_INT32(result);
1060 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT16, PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int4_bool()

Datum int4_bool ( PG_FUNCTION_ARGS  )

Definition at line 362 of file int.c.

363 {
364  if (PG_GETARG_INT32(0) == 0)
365  PG_RETURN_BOOL(false);
366  else
367  PG_RETURN_BOOL(true);
368 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4abs()

Datum int4abs ( PG_FUNCTION_ARGS  )

Definition at line 1191 of file int.c.

1192 {
1193  int32 arg1 = PG_GETARG_INT32(0);
1194  int32 result;
1195 
1196  if (unlikely(arg1 == PG_INT32_MIN))
1197  ereport(ERROR,
1198  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1199  errmsg("integer out of range")));
1200  result = (arg1 < 0) ? -arg1 : arg1;
1201  PG_RETURN_INT32(result);
1202 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

◆ int4and()

Datum int4and ( PG_FUNCTION_ARGS  )

Definition at line 1393 of file int.c.

1394 {
1395  int32 arg1 = PG_GETARG_INT32(0);
1396  int32 arg2 = PG_GETARG_INT32(1);
1397 
1398  PG_RETURN_INT32(arg1 & arg2);
1399 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4div()

Datum int4div ( PG_FUNCTION_ARGS  )

Definition at line 833 of file int.c.

834 {
835  int32 arg1 = PG_GETARG_INT32(0);
836  int32 arg2 = PG_GETARG_INT32(1);
837  int32 result;
838 
839  if (arg2 == 0)
840  {
841  ereport(ERROR,
842  (errcode(ERRCODE_DIVISION_BY_ZERO),
843  errmsg("division by zero")));
844  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
845  PG_RETURN_NULL();
846  }
847 
848  /*
849  * INT_MIN / -1 is problematic, since the result can't be represented on a
850  * two's-complement machine. Some machines produce INT_MIN, some produce
851  * zero, some throw an exception. We can dodge the problem by recognizing
852  * that division by -1 is the same as negation.
853  */
854  if (arg2 == -1)
855  {
856  if (unlikely(arg1 == PG_INT32_MIN))
857  ereport(ERROR,
858  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
859  errmsg("integer out of range")));
860  result = -arg1;
861  PG_RETURN_INT32(result);
862  }
863 
864  /* No overflow is possible */
865 
866  result = arg1 / arg2;
867 
868  PG_RETURN_INT32(result);
869 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int4eq()

Datum int4eq ( PG_FUNCTION_ARGS  )

Definition at line 396 of file int.c.

397 {
398  int32 arg1 = PG_GETARG_INT32(0);
399  int32 arg2 = PG_GETARG_INT32(1);
400 
401  PG_RETURN_BOOL(arg1 == arg2);
402 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4gcd()

Datum int4gcd ( PG_FUNCTION_ARGS  )

Definition at line 1294 of file int.c.

1295 {
1296  int32 arg1 = PG_GETARG_INT32(0);
1297  int32 arg2 = PG_GETARG_INT32(1);
1298  int32 result;
1299 
1300  result = int4gcd_internal(arg1, arg2);
1301 
1302  PG_RETURN_INT32(result);
1303 }
static int32 int4gcd_internal(int32 arg1, int32 arg2)
Definition: int.c:1233

References int4gcd_internal(), PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4gcd_internal()

static int32 int4gcd_internal ( int32  arg1,
int32  arg2 
)
static

Definition at line 1233 of file int.c.

1234 {
1235  int32 swap;
1236  int32 a1,
1237  a2;
1238 
1239  /*
1240  * Put the greater absolute value in arg1.
1241  *
1242  * This would happen automatically in the loop below, but avoids an
1243  * expensive modulo operation, and simplifies the special-case handling
1244  * for INT_MIN below.
1245  *
1246  * We do this in negative space in order to handle INT_MIN.
1247  */
1248  a1 = (arg1 < 0) ? arg1 : -arg1;
1249  a2 = (arg2 < 0) ? arg2 : -arg2;
1250  if (a1 > a2)
1251  {
1252  swap = arg1;
1253  arg1 = arg2;
1254  arg2 = swap;
1255  }
1256 
1257  /* Special care needs to be taken with INT_MIN. See comments above. */
1258  if (arg1 == PG_INT32_MIN)
1259  {
1260  if (arg2 == 0 || arg2 == PG_INT32_MIN)
1261  ereport(ERROR,
1262  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1263  errmsg("integer out of range")));
1264 
1265  /*
1266  * Some machines throw a floating-point exception for INT_MIN % -1,
1267  * which is a bit silly since the correct answer is perfectly
1268  * well-defined, namely zero. Guard against this and just return the
1269  * result, gcd(INT_MIN, -1) = 1.
1270  */
1271  if (arg2 == -1)
1272  return 1;
1273  }
1274 
1275  /* Use the Euclidean algorithm to find the GCD */
1276  while (arg2 != 0)
1277  {
1278  swap = arg2;
1279  arg2 = arg1 % arg2;
1280  arg1 = swap;
1281  }
1282 
1283  /*
1284  * Make sure the result is positive. (We know we don't have INT_MIN
1285  * anymore).
1286  */
1287  if (arg1 < 0)
1288  arg1 = -arg1;
1289 
1290  return arg1;
1291 }
static const FormData_pg_attribute a1
Definition: heap.c:142
static const FormData_pg_attribute a2
Definition: heap.c:156

References a1, a2, ereport, errcode(), errmsg(), ERROR, and PG_INT32_MIN.

Referenced by int4gcd(), and int4lcm().

◆ int4ge()

Datum int4ge ( PG_FUNCTION_ARGS  )

Definition at line 441 of file int.c.

442 {
443  int32 arg1 = PG_GETARG_INT32(0);
444  int32 arg2 = PG_GETARG_INT32(1);
445 
446  PG_RETURN_BOOL(arg1 >= arg2);
447 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4gt()

Datum int4gt ( PG_FUNCTION_ARGS  )

Definition at line 432 of file int.c.

433 {
434  int32 arg1 = PG_GETARG_INT32(0);
435  int32 arg2 = PG_GETARG_INT32(1);
436 
437  PG_RETURN_BOOL(arg1 > arg2);
438 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4in()

Datum int4in ( PG_FUNCTION_ARGS  )

Definition at line 287 of file int.c.

288 {
289  char *num = PG_GETARG_CSTRING(0);
290 
291  PG_RETURN_INT32(pg_strtoint32_safe(num, fcinfo->context));
292 }
int32 pg_strtoint32_safe(const char *s, Node *escontext)
Definition: numutils.c:389

References PG_GETARG_CSTRING, PG_RETURN_INT32, and pg_strtoint32_safe().

Referenced by executeItemOptUnwrapTarget(), inet_client_port(), inet_server_port(), and pg_stat_get_backend_client_port().

◆ int4inc()

Datum int4inc ( PG_FUNCTION_ARGS  )

Definition at line 872 of file int.c.

873 {
875  int32 result;
876 
877  if (unlikely(pg_add_s32_overflow(arg, 1, &result)))
878  ereport(ERROR,
879  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
880  errmsg("integer out of range")));
881 
882  PG_RETURN_INT32(result);
883 }

References arg, ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int4larger()

Datum int4larger ( PG_FUNCTION_ARGS  )

Definition at line 1364 of file int.c.

1365 {
1366  int32 arg1 = PG_GETARG_INT32(0);
1367  int32 arg2 = PG_GETARG_INT32(1);
1368 
1369  PG_RETURN_INT32((arg1 > arg2) ? arg1 : arg2);
1370 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4lcm()

Datum int4lcm ( PG_FUNCTION_ARGS  )

Definition at line 1309 of file int.c.

1310 {
1311  int32 arg1 = PG_GETARG_INT32(0);
1312  int32 arg2 = PG_GETARG_INT32(1);
1313  int32 gcd;
1314  int32 result;
1315 
1316  /*
1317  * Handle lcm(x, 0) = lcm(0, x) = 0 as a special case. This prevents a
1318  * division-by-zero error below when x is zero, and an overflow error from
1319  * the GCD computation when x = INT_MIN.
1320  */
1321  if (arg1 == 0 || arg2 == 0)
1322  PG_RETURN_INT32(0);
1323 
1324  /* lcm(x, y) = abs(x / gcd(x, y) * y) */
1325  gcd = int4gcd_internal(arg1, arg2);
1326  arg1 = arg1 / gcd;
1327 
1328  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
1329  ereport(ERROR,
1330  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1331  errmsg("integer out of range")));
1332 
1333  /* If the result is INT_MIN, it cannot be represented. */
1334  if (unlikely(result == PG_INT32_MIN))
1335  ereport(ERROR,
1336  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1337  errmsg("integer out of range")));
1338 
1339  if (result < 0)
1340  result = -result;
1341 
1342  PG_RETURN_INT32(result);
1343 }
static uint32 gcd(uint32 a, uint32 b)

References ereport, errcode(), errmsg(), ERROR, gcd(), int4gcd_internal(), PG_GETARG_INT32, PG_INT32_MIN, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int4le()

Datum int4le ( PG_FUNCTION_ARGS  )

Definition at line 423 of file int.c.

424 {
425  int32 arg1 = PG_GETARG_INT32(0);
426  int32 arg2 = PG_GETARG_INT32(1);
427 
428  PG_RETURN_BOOL(arg1 <= arg2);
429 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4lt()

Datum int4lt ( PG_FUNCTION_ARGS  )

Definition at line 414 of file int.c.

415 {
416  int32 arg1 = PG_GETARG_INT32(0);
417  int32 arg2 = PG_GETARG_INT32(1);
418 
419  PG_RETURN_BOOL(arg1 < arg2);
420 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4mi()

Datum int4mi ( PG_FUNCTION_ARGS  )

Definition at line 805 of file int.c.

806 {
807  int32 arg1 = PG_GETARG_INT32(0);
808  int32 arg2 = PG_GETARG_INT32(1);
809  int32 result;
810 
811  if (unlikely(pg_sub_s32_overflow(arg1, arg2, &result)))
812  ereport(ERROR,
813  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
814  errmsg("integer out of range")));
815  PG_RETURN_INT32(result);
816 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, pg_sub_s32_overflow(), and unlikely.

◆ int4mod()

Datum int4mod ( PG_FUNCTION_ARGS  )

Definition at line 1130 of file int.c.

1131 {
1132  int32 arg1 = PG_GETARG_INT32(0);
1133  int32 arg2 = PG_GETARG_INT32(1);
1134 
1135  if (unlikely(arg2 == 0))
1136  {
1137  ereport(ERROR,
1138  (errcode(ERRCODE_DIVISION_BY_ZERO),
1139  errmsg("division by zero")));
1140  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1141  PG_RETURN_NULL();
1142  }
1143 
1144  /*
1145  * Some machines throw a floating-point exception for INT_MIN % -1, which
1146  * is a bit silly since the correct answer is perfectly well-defined,
1147  * namely zero.
1148  */
1149  if (arg2 == -1)
1150  PG_RETURN_INT32(0);
1151 
1152  /* No overflow is possible */
1153 
1154  PG_RETURN_INT32(arg1 % arg2);
1155 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_RETURN_INT32, PG_RETURN_NULL, and unlikely.

◆ int4mul()

Datum int4mul ( PG_FUNCTION_ARGS  )

Definition at line 819 of file int.c.

820 {
821  int32 arg1 = PG_GETARG_INT32(0);
822  int32 arg2 = PG_GETARG_INT32(1);
823  int32 result;
824 
825  if (unlikely(pg_mul_s32_overflow(arg1, arg2, &result)))
826  ereport(ERROR,
827  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
828  errmsg("integer out of range")));
829  PG_RETURN_INT32(result);
830 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, pg_mul_s32_overflow(), PG_RETURN_INT32, and unlikely.

◆ int4ne()

Datum int4ne ( PG_FUNCTION_ARGS  )

Definition at line 405 of file int.c.

406 {
407  int32 arg1 = PG_GETARG_INT32(0);
408  int32 arg2 = PG_GETARG_INT32(1);
409 
410  PG_RETURN_BOOL(arg1 != arg2);
411 }

References PG_GETARG_INT32, and PG_RETURN_BOOL.

◆ int4not()

Datum int4not ( PG_FUNCTION_ARGS  )

Definition at line 1438 of file int.c.

1439 {
1440  int32 arg1 = PG_GETARG_INT32(0);
1441 
1442  PG_RETURN_INT32(~arg1);
1443 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4or()

Datum int4or ( PG_FUNCTION_ARGS  )

Definition at line 1402 of file int.c.

1403 {
1404  int32 arg1 = PG_GETARG_INT32(0);
1405  int32 arg2 = PG_GETARG_INT32(1);
1406 
1407  PG_RETURN_INT32(arg1 | arg2);
1408 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4out()

Datum int4out ( PG_FUNCTION_ARGS  )

Definition at line 298 of file int.c.

299 {
300  int32 arg1 = PG_GETARG_INT32(0);
301  char *result = (char *) palloc(12); /* sign, 10 digits, '\0' */
302 
303  pg_ltoa(arg1, result);
304  PG_RETURN_CSTRING(result);
305 }
int pg_ltoa(int32 value, char *a)
Definition: numutils.c:1122

References palloc(), PG_GETARG_INT32, pg_ltoa(), and PG_RETURN_CSTRING.

Referenced by int4_to_char(), and jsonb_subscript_check_subscripts().

◆ int4pl()

Datum int4pl ( PG_FUNCTION_ARGS  )

Definition at line 791 of file int.c.

792 {
793  int32 arg1 = PG_GETARG_INT32(0);
794  int32 arg2 = PG_GETARG_INT32(1);
795  int32 result;
796 
797  if (unlikely(pg_add_s32_overflow(arg1, arg2, &result)))
798  ereport(ERROR,
799  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
800  errmsg("integer out of range")));
801  PG_RETURN_INT32(result);
802 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s32_overflow(), PG_GETARG_INT32, PG_RETURN_INT32, and unlikely.

◆ int4recv()

Datum int4recv ( PG_FUNCTION_ARGS  )

Definition at line 311 of file int.c.

312 {
314 
316 }

References buf, PG_GETARG_POINTER, PG_RETURN_INT32, and pq_getmsgint().

◆ int4send()

Datum int4send ( PG_FUNCTION_ARGS  )

Definition at line 322 of file int.c.

323 {
324  int32 arg1 = PG_GETARG_INT32(0);
326 
328  pq_sendint32(&buf, arg1);
330 }
static void pq_sendint32(StringInfo buf, uint32 i)
Definition: pqformat.h:144

References buf, PG_GETARG_INT32, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint32().

◆ int4shl()

Datum int4shl ( PG_FUNCTION_ARGS  )

Definition at line 1420 of file int.c.

1421 {
1422  int32 arg1 = PG_GETARG_INT32(0);
1423  int32 arg2 = PG_GETARG_INT32(1);
1424 
1425  PG_RETURN_INT32(arg1 << arg2);
1426 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4shr()

Datum int4shr ( PG_FUNCTION_ARGS  )

Definition at line 1429 of file int.c.

1430 {
1431  int32 arg1 = PG_GETARG_INT32(0);
1432  int32 arg2 = PG_GETARG_INT32(1);
1433 
1434  PG_RETURN_INT32(arg1 >> arg2);
1435 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4smaller()

Datum int4smaller ( PG_FUNCTION_ARGS  )

Definition at line 1373 of file int.c.

1374 {
1375  int32 arg1 = PG_GETARG_INT32(0);
1376  int32 arg2 = PG_GETARG_INT32(1);
1377 
1378  PG_RETURN_INT32((arg1 < arg2) ? arg1 : arg2);
1379 }

References PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4um()

Datum int4um ( PG_FUNCTION_ARGS  )

Definition at line 771 of file int.c.

772 {
774 
775  if (unlikely(arg == PG_INT32_MIN))
776  ereport(ERROR,
777  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
778  errmsg("integer out of range")));
780 }

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_INT32_MIN, PG_RETURN_INT32, and unlikely.

◆ int4up()

Datum int4up ( PG_FUNCTION_ARGS  )

Definition at line 783 of file int.c.

784 {
786 
788 }

References arg, PG_GETARG_INT32, and PG_RETURN_INT32.

◆ int4xor()

Datum int4xor ( PG_FUNCTION_ARGS  )

Definition at line 1411 of file int.c.

1412 {
1413  int32 arg1 = PG_GETARG_INT32(0);
1414  int32 arg2 = PG_GETARG_INT32(1);
1415 
1416  PG_RETURN_INT32(arg1 ^ arg2);
1417 }

References PG_GETARG_INT32, and PG_RETURN_INT32.