PostgreSQL Source Code  git master
int8.c File Reference
#include "postgres.h"
#include <ctype.h>
#include <limits.h>
#include <math.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/builtins.h"
#include "utils/lsyscache.h"
Include dependency graph for int8.c:

Go to the source code of this file.

Data Structures

struct  generate_series_fctx
 

Functions

Datum int8in (PG_FUNCTION_ARGS)
 
Datum int8out (PG_FUNCTION_ARGS)
 
Datum int8recv (PG_FUNCTION_ARGS)
 
Datum int8send (PG_FUNCTION_ARGS)
 
Datum int8eq (PG_FUNCTION_ARGS)
 
Datum int8ne (PG_FUNCTION_ARGS)
 
Datum int8lt (PG_FUNCTION_ARGS)
 
Datum int8gt (PG_FUNCTION_ARGS)
 
Datum int8le (PG_FUNCTION_ARGS)
 
Datum int8ge (PG_FUNCTION_ARGS)
 
Datum int84eq (PG_FUNCTION_ARGS)
 
Datum int84ne (PG_FUNCTION_ARGS)
 
Datum int84lt (PG_FUNCTION_ARGS)
 
Datum int84gt (PG_FUNCTION_ARGS)
 
Datum int84le (PG_FUNCTION_ARGS)
 
Datum int84ge (PG_FUNCTION_ARGS)
 
Datum int48eq (PG_FUNCTION_ARGS)
 
Datum int48ne (PG_FUNCTION_ARGS)
 
Datum int48lt (PG_FUNCTION_ARGS)
 
Datum int48gt (PG_FUNCTION_ARGS)
 
Datum int48le (PG_FUNCTION_ARGS)
 
Datum int48ge (PG_FUNCTION_ARGS)
 
Datum int82eq (PG_FUNCTION_ARGS)
 
Datum int82ne (PG_FUNCTION_ARGS)
 
Datum int82lt (PG_FUNCTION_ARGS)
 
Datum int82gt (PG_FUNCTION_ARGS)
 
Datum int82le (PG_FUNCTION_ARGS)
 
Datum int82ge (PG_FUNCTION_ARGS)
 
Datum int28eq (PG_FUNCTION_ARGS)
 
Datum int28ne (PG_FUNCTION_ARGS)
 
Datum int28lt (PG_FUNCTION_ARGS)
 
Datum int28gt (PG_FUNCTION_ARGS)
 
Datum int28le (PG_FUNCTION_ARGS)
 
Datum int28ge (PG_FUNCTION_ARGS)
 
Datum in_range_int8_int8 (PG_FUNCTION_ARGS)
 
Datum int8um (PG_FUNCTION_ARGS)
 
Datum int8up (PG_FUNCTION_ARGS)
 
Datum int8pl (PG_FUNCTION_ARGS)
 
Datum int8mi (PG_FUNCTION_ARGS)
 
Datum int8mul (PG_FUNCTION_ARGS)
 
Datum int8div (PG_FUNCTION_ARGS)
 
Datum int8abs (PG_FUNCTION_ARGS)
 
Datum int8mod (PG_FUNCTION_ARGS)
 
static int64 int8gcd_internal (int64 arg1, int64 arg2)
 
Datum int8gcd (PG_FUNCTION_ARGS)
 
Datum int8lcm (PG_FUNCTION_ARGS)
 
Datum int8inc (PG_FUNCTION_ARGS)
 
Datum int8dec (PG_FUNCTION_ARGS)
 
Datum int8inc_any (PG_FUNCTION_ARGS)
 
Datum int8inc_float8_float8 (PG_FUNCTION_ARGS)
 
Datum int8dec_any (PG_FUNCTION_ARGS)
 
Datum int8inc_support (PG_FUNCTION_ARGS)
 
Datum int8larger (PG_FUNCTION_ARGS)
 
Datum int8smaller (PG_FUNCTION_ARGS)
 
Datum int84pl (PG_FUNCTION_ARGS)
 
Datum int84mi (PG_FUNCTION_ARGS)
 
Datum int84mul (PG_FUNCTION_ARGS)
 
Datum int84div (PG_FUNCTION_ARGS)
 
Datum int48pl (PG_FUNCTION_ARGS)
 
Datum int48mi (PG_FUNCTION_ARGS)
 
Datum int48mul (PG_FUNCTION_ARGS)
 
Datum int48div (PG_FUNCTION_ARGS)
 
Datum int82pl (PG_FUNCTION_ARGS)
 
Datum int82mi (PG_FUNCTION_ARGS)
 
Datum int82mul (PG_FUNCTION_ARGS)
 
Datum int82div (PG_FUNCTION_ARGS)
 
Datum int28pl (PG_FUNCTION_ARGS)
 
Datum int28mi (PG_FUNCTION_ARGS)
 
Datum int28mul (PG_FUNCTION_ARGS)
 
Datum int28div (PG_FUNCTION_ARGS)
 
Datum int8and (PG_FUNCTION_ARGS)
 
Datum int8or (PG_FUNCTION_ARGS)
 
Datum int8xor (PG_FUNCTION_ARGS)
 
Datum int8not (PG_FUNCTION_ARGS)
 
Datum int8shl (PG_FUNCTION_ARGS)
 
Datum int8shr (PG_FUNCTION_ARGS)
 
Datum int48 (PG_FUNCTION_ARGS)
 
Datum int84 (PG_FUNCTION_ARGS)
 
Datum int28 (PG_FUNCTION_ARGS)
 
Datum int82 (PG_FUNCTION_ARGS)
 
Datum i8tod (PG_FUNCTION_ARGS)
 
Datum dtoi8 (PG_FUNCTION_ARGS)
 
Datum i8tof (PG_FUNCTION_ARGS)
 
Datum ftoi8 (PG_FUNCTION_ARGS)
 
Datum i8tooid (PG_FUNCTION_ARGS)
 
Datum oidtoi8 (PG_FUNCTION_ARGS)
 
Datum generate_series_int8 (PG_FUNCTION_ARGS)
 
Datum generate_series_step_int8 (PG_FUNCTION_ARGS)
 
Datum generate_series_int8_support (PG_FUNCTION_ARGS)
 

Function Documentation

◆ dtoi8()

Datum dtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1298 of file int8.c.

1299 {
1300  float8 num = PG_GETARG_FLOAT8(0);
1301 
1302  /*
1303  * Get rid of any fractional part in the input. This is so we don't fail
1304  * on just-out-of-range values that would round into range. Note
1305  * assumption that rint() will pass through a NaN or Inf unchanged.
1306  */
1307  num = rint(num);
1308 
1309  /* Range check */
1310  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
1311  ereport(ERROR,
1312  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1313  errmsg("bigint out of range")));
1314 
1315  PG_RETURN_INT64((int64) num);
1316 }
double float8
Definition: c.h:619
#define FLOAT8_FITS_IN_INT64(num)
Definition: c.h:1105
#define unlikely(x)
Definition: c.h:300
int errcode(int sqlerrcode)
Definition: elog.c:858
int errmsg(const char *fmt,...)
Definition: elog.c:1069
#define ERROR
Definition: elog.h:39
#define ereport(elevel,...)
Definition: elog.h:149
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:282
#define PG_RETURN_INT64(x)
Definition: fmgr.h:368

References ereport, errcode(), errmsg(), ERROR, FLOAT8_FITS_IN_INT64, PG_GETARG_FLOAT8, PG_RETURN_INT64, and unlikely.

Referenced by int8_to_char().

◆ ftoi8()

Datum ftoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1333 of file int8.c.

1334 {
1335  float4 num = PG_GETARG_FLOAT4(0);
1336 
1337  /*
1338  * Get rid of any fractional part in the input. This is so we don't fail
1339  * on just-out-of-range values that would round into range. Note
1340  * assumption that rint() will pass through a NaN or Inf unchanged.
1341  */
1342  num = rint(num);
1343 
1344  /* Range check */
1345  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
1346  ereport(ERROR,
1347  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1348  errmsg("bigint out of range")));
1349 
1350  PG_RETURN_INT64((int64) num);
1351 }
#define FLOAT4_FITS_IN_INT64(num)
Definition: c.h:1099
float float4
Definition: c.h:618
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:281

References ereport, errcode(), errmsg(), ERROR, FLOAT4_FITS_IN_INT64, PG_GETARG_FLOAT4, PG_RETURN_INT64, and unlikely.

◆ generate_series_int8()

Datum generate_series_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1378 of file int8.c.

1379 {
1380  return generate_series_step_int8(fcinfo);
1381 }
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1384

References generate_series_step_int8().

◆ generate_series_int8_support()

Datum generate_series_int8_support ( PG_FUNCTION_ARGS  )

Definition at line 1460 of file int8.c.

1461 {
1462  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1463  Node *ret = NULL;
1464 
1465  if (IsA(rawreq, SupportRequestRows))
1466  {
1467  /* Try to estimate the number of rows returned */
1468  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1469 
1470  if (is_funcclause(req->node)) /* be paranoid */
1471  {
1472  List *args = ((FuncExpr *) req->node)->args;
1473  Node *arg1,
1474  *arg2,
1475  *arg3;
1476 
1477  /* We can use estimated argument values here */
1479  arg2 = estimate_expression_value(req->root, lsecond(args));
1480  if (list_length(args) >= 3)
1481  arg3 = estimate_expression_value(req->root, lthird(args));
1482  else
1483  arg3 = NULL;
1484 
1485  /*
1486  * If any argument is constant NULL, we can safely assume that
1487  * zero rows are returned. Otherwise, if they're all non-NULL
1488  * constants, we can calculate the number of rows that will be
1489  * returned. Use double arithmetic to avoid overflow hazards.
1490  */
1491  if ((IsA(arg1, Const) &&
1492  ((Const *) arg1)->constisnull) ||
1493  (IsA(arg2, Const) &&
1494  ((Const *) arg2)->constisnull) ||
1495  (arg3 != NULL && IsA(arg3, Const) &&
1496  ((Const *) arg3)->constisnull))
1497  {
1498  req->rows = 0;
1499  ret = (Node *) req;
1500  }
1501  else if (IsA(arg1, Const) &&
1502  IsA(arg2, Const) &&
1503  (arg3 == NULL || IsA(arg3, Const)))
1504  {
1505  double start,
1506  finish,
1507  step;
1508 
1509  start = DatumGetInt64(((Const *) arg1)->constvalue);
1510  finish = DatumGetInt64(((Const *) arg2)->constvalue);
1511  step = arg3 ? DatumGetInt64(((Const *) arg3)->constvalue) : 1;
1512 
1513  /* This equation works for either sign of step */
1514  if (step != 0)
1515  {
1516  req->rows = floor((finish - start + step) / step);
1517  ret = (Node *) req;
1518  }
1519  }
1520  }
1521  }
1522 
1523  PG_RETURN_POINTER(ret);
1524 }
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2312
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:276
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:361
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:67
#define IsA(nodeptr, _type_)
Definition: nodes.h:179
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 int64 DatumGetInt64(Datum X)
Definition: postgres.h:385
Definition: pg_list.h:54
Definition: nodes.h:129
struct PlannerInfo * root
Definition: supportnodes.h:163

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

◆ generate_series_step_int8()

Datum generate_series_step_int8 ( PG_FUNCTION_ARGS  )

Definition at line 1384 of file int8.c.

1385 {
1386  FuncCallContext *funcctx;
1387  generate_series_fctx *fctx;
1388  int64 result;
1389  MemoryContext oldcontext;
1390 
1391  /* stuff done only on the first call of the function */
1392  if (SRF_IS_FIRSTCALL())
1393  {
1394  int64 start = PG_GETARG_INT64(0);
1395  int64 finish = PG_GETARG_INT64(1);
1396  int64 step = 1;
1397 
1398  /* see if we were given an explicit step size */
1399  if (PG_NARGS() == 3)
1400  step = PG_GETARG_INT64(2);
1401  if (step == 0)
1402  ereport(ERROR,
1403  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1404  errmsg("step size cannot equal zero")));
1405 
1406  /* create a function context for cross-call persistence */
1407  funcctx = SRF_FIRSTCALL_INIT();
1408 
1409  /*
1410  * switch to memory context appropriate for multiple function calls
1411  */
1412  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1413 
1414  /* allocate memory for user context */
1415  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1416 
1417  /*
1418  * Use fctx to keep state from call to call. Seed current with the
1419  * original start value
1420  */
1421  fctx->current = start;
1422  fctx->finish = finish;
1423  fctx->step = step;
1424 
1425  funcctx->user_fctx = fctx;
1426  MemoryContextSwitchTo(oldcontext);
1427  }
1428 
1429  /* stuff done on every call of the function */
1430  funcctx = SRF_PERCALL_SETUP();
1431 
1432  /*
1433  * get the saved state and use current as the result for this iteration
1434  */
1435  fctx = funcctx->user_fctx;
1436  result = fctx->current;
1437 
1438  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1439  (fctx->step < 0 && fctx->current >= fctx->finish))
1440  {
1441  /*
1442  * Increment current in preparation for next iteration. If next-value
1443  * computation overflows, this is the final result.
1444  */
1445  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1446  fctx->step = 0;
1447 
1448  /* do when there is more left to send */
1449  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1450  }
1451  else
1452  /* do when there is no more left */
1453  SRF_RETURN_DONE(funcctx);
1454 }
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1790
#define PG_NARGS()
Definition: fmgr.h:203
#define PG_GETARG_INT64(n)
Definition: fmgr.h:283
#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_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
void * palloc(Size size)
Definition: mcxt.c:1226
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:138
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, Int64GetDatum(), MemoryContextSwitchTo(), FuncCallContext::multi_call_memory_ctx, palloc(), pg_add_s64_overflow(), PG_GETARG_INT64, PG_NARGS, 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_int8().

◆ i8tod()

Datum i8tod ( PG_FUNCTION_ARGS  )

Definition at line 1284 of file int8.c.

1285 {
1286  int64 arg = PG_GETARG_INT64(0);
1287  float8 result;
1288 
1289  result = arg;
1290 
1291  PG_RETURN_FLOAT8(result);
1292 }
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:367
void * arg

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT8.

◆ i8tof()

Datum i8tof ( PG_FUNCTION_ARGS  )

Definition at line 1319 of file int8.c.

1320 {
1321  int64 arg = PG_GETARG_INT64(0);
1322  float4 result;
1323 
1324  result = arg;
1325 
1326  PG_RETURN_FLOAT4(result);
1327 }
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:366

References arg, PG_GETARG_INT64, and PG_RETURN_FLOAT4.

◆ i8tooid()

Datum i8tooid ( PG_FUNCTION_ARGS  )

Definition at line 1354 of file int8.c.

1355 {
1356  int64 arg = PG_GETARG_INT64(0);
1357 
1358  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1359  ereport(ERROR,
1360  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1361  errmsg("OID out of range")));
1362 
1363  PG_RETURN_OID((Oid) arg);
1364 }
#define PG_UINT32_MAX
Definition: c.h:579
#define PG_RETURN_OID(x)
Definition: fmgr.h:360
unsigned int Oid
Definition: postgres_ext.h:31

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_OID, PG_UINT32_MAX, and unlikely.

◆ in_range_int8_int8()

Datum in_range_int8_int8 ( PG_FUNCTION_ARGS  )

Definition at line 402 of file int8.c.

403 {
404  int64 val = PG_GETARG_INT64(0);
405  int64 base = PG_GETARG_INT64(1);
406  int64 offset = PG_GETARG_INT64(2);
407  bool sub = PG_GETARG_BOOL(3);
408  bool less = PG_GETARG_BOOL(4);
409  int64 sum;
410 
411  if (offset < 0)
412  ereport(ERROR,
413  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
414  errmsg("invalid preceding or following size in window function")));
415 
416  if (sub)
417  offset = -offset; /* cannot overflow */
418 
419  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
420  {
421  /*
422  * If sub is false, the true sum is surely more than val, so correct
423  * answer is the same as "less". If sub is true, the true sum is
424  * surely less than val, so the answer is "!less".
425  */
426  PG_RETURN_BOOL(sub ? !less : less);
427  }
428 
429  if (less)
430  PG_RETURN_BOOL(val <= sum);
431  else
432  PG_RETURN_BOOL(val >= sum);
433 }
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:274
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:359
long val
Definition: informix.c:664

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

◆ int28()

Datum int28 ( PG_FUNCTION_ARGS  )

Definition at line 1263 of file int8.c.

1264 {
1265  int16 arg = PG_GETARG_INT16(0);
1266 
1267  PG_RETURN_INT64((int64) arg);
1268 }
signed short int16
Definition: c.h:482
#define PG_GETARG_INT16(n)
Definition: fmgr.h:271

References arg, PG_GETARG_INT16, and PG_RETURN_INT64.

◆ int28div()

Datum int28div ( PG_FUNCTION_ARGS  )

Definition at line 1156 of file int8.c.

1157 {
1158  int16 arg1 = PG_GETARG_INT16(0);
1159  int64 arg2 = PG_GETARG_INT64(1);
1160 
1161  if (unlikely(arg2 == 0))
1162  {
1163  ereport(ERROR,
1164  (errcode(ERRCODE_DIVISION_BY_ZERO),
1165  errmsg("division by zero")));
1166  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1167  PG_RETURN_NULL();
1168  }
1169 
1170  /* No overflow is possible */
1171  PG_RETURN_INT64((int64) arg1 / arg2);
1172 }
#define PG_RETURN_NULL()
Definition: fmgr.h:345

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

◆ int28eq()

Datum int28eq ( PG_FUNCTION_ARGS  )

Definition at line 342 of file int8.c.

343 {
344  int16 val1 = PG_GETARG_INT16(0);
345  int64 val2 = PG_GETARG_INT64(1);
346 
347  PG_RETURN_BOOL(val1 == val2);
348 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28ge()

Datum int28ge ( PG_FUNCTION_ARGS  )

Definition at line 387 of file int8.c.

388 {
389  int16 val1 = PG_GETARG_INT16(0);
390  int64 val2 = PG_GETARG_INT64(1);
391 
392  PG_RETURN_BOOL(val1 >= val2);
393 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28gt()

Datum int28gt ( PG_FUNCTION_ARGS  )

Definition at line 369 of file int8.c.

370 {
371  int16 val1 = PG_GETARG_INT16(0);
372  int64 val2 = PG_GETARG_INT64(1);
373 
374  PG_RETURN_BOOL(val1 > val2);
375 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28le()

Datum int28le ( PG_FUNCTION_ARGS  )

Definition at line 378 of file int8.c.

379 {
380  int16 val1 = PG_GETARG_INT16(0);
381  int64 val2 = PG_GETARG_INT64(1);
382 
383  PG_RETURN_BOOL(val1 <= val2);
384 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28lt()

Datum int28lt ( PG_FUNCTION_ARGS  )

Definition at line 360 of file int8.c.

361 {
362  int16 val1 = PG_GETARG_INT16(0);
363  int64 val2 = PG_GETARG_INT64(1);
364 
365  PG_RETURN_BOOL(val1 < val2);
366 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28mi()

Datum int28mi ( PG_FUNCTION_ARGS  )

Definition at line 1128 of file int8.c.

1129 {
1130  int16 arg1 = PG_GETARG_INT16(0);
1131  int64 arg2 = PG_GETARG_INT64(1);
1132  int64 result;
1133 
1134  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1135  ereport(ERROR,
1136  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1137  errmsg("bigint out of range")));
1138  PG_RETURN_INT64(result);
1139 }
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

◆ int28mul()

Datum int28mul ( PG_FUNCTION_ARGS  )

Definition at line 1142 of file int8.c.

1143 {
1144  int16 arg1 = PG_GETARG_INT16(0);
1145  int64 arg2 = PG_GETARG_INT64(1);
1146  int64 result;
1147 
1148  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1149  ereport(ERROR,
1150  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1151  errmsg("bigint out of range")));
1152  PG_RETURN_INT64(result);
1153 }
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

◆ int28ne()

Datum int28ne ( PG_FUNCTION_ARGS  )

Definition at line 351 of file int8.c.

352 {
353  int16 val1 = PG_GETARG_INT16(0);
354  int64 val2 = PG_GETARG_INT64(1);
355 
356  PG_RETURN_BOOL(val1 != val2);
357 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int28pl()

Datum int28pl ( PG_FUNCTION_ARGS  )

Definition at line 1114 of file int8.c.

1115 {
1116  int16 arg1 = PG_GETARG_INT16(0);
1117  int64 arg2 = PG_GETARG_INT64(1);
1118  int64 result;
1119 
1120  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1121  ereport(ERROR,
1122  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1123  errmsg("bigint out of range")));
1124  PG_RETURN_INT64(result);
1125 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

◆ int48()

Datum int48 ( PG_FUNCTION_ARGS  )

Definition at line 1242 of file int8.c.

1243 {
1244  int32 arg = PG_GETARG_INT32(0);
1245 
1246  PG_RETURN_INT64((int64) arg);
1247 }
signed int int32
Definition: c.h:483
#define PG_GETARG_INT32(n)
Definition: fmgr.h:269

References arg, PG_GETARG_INT32, and PG_RETURN_INT64.

◆ int48div()

Datum int48div ( PG_FUNCTION_ARGS  )

Definition at line 1014 of file int8.c.

1015 {
1016  int32 arg1 = PG_GETARG_INT32(0);
1017  int64 arg2 = PG_GETARG_INT64(1);
1018 
1019  if (unlikely(arg2 == 0))
1020  {
1021  ereport(ERROR,
1022  (errcode(ERRCODE_DIVISION_BY_ZERO),
1023  errmsg("division by zero")));
1024  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1025  PG_RETURN_NULL();
1026  }
1027 
1028  /* No overflow is possible */
1029  PG_RETURN_INT64((int64) arg1 / arg2);
1030 }

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

◆ int48eq()

Datum int48eq ( PG_FUNCTION_ARGS  )

Definition at line 228 of file int8.c.

229 {
230  int32 val1 = PG_GETARG_INT32(0);
231  int64 val2 = PG_GETARG_INT64(1);
232 
233  PG_RETURN_BOOL(val1 == val2);
234 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48ge()

Datum int48ge ( PG_FUNCTION_ARGS  )

Definition at line 273 of file int8.c.

274 {
275  int32 val1 = PG_GETARG_INT32(0);
276  int64 val2 = PG_GETARG_INT64(1);
277 
278  PG_RETURN_BOOL(val1 >= val2);
279 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48gt()

Datum int48gt ( PG_FUNCTION_ARGS  )

Definition at line 255 of file int8.c.

256 {
257  int32 val1 = PG_GETARG_INT32(0);
258  int64 val2 = PG_GETARG_INT64(1);
259 
260  PG_RETURN_BOOL(val1 > val2);
261 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48le()

Datum int48le ( PG_FUNCTION_ARGS  )

Definition at line 264 of file int8.c.

265 {
266  int32 val1 = PG_GETARG_INT32(0);
267  int64 val2 = PG_GETARG_INT64(1);
268 
269  PG_RETURN_BOOL(val1 <= val2);
270 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48lt()

Datum int48lt ( PG_FUNCTION_ARGS  )

Definition at line 246 of file int8.c.

247 {
248  int32 val1 = PG_GETARG_INT32(0);
249  int64 val2 = PG_GETARG_INT64(1);
250 
251  PG_RETURN_BOOL(val1 < val2);
252 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48mi()

Datum int48mi ( PG_FUNCTION_ARGS  )

Definition at line 986 of file int8.c.

987 {
988  int32 arg1 = PG_GETARG_INT32(0);
989  int64 arg2 = PG_GETARG_INT64(1);
990  int64 result;
991 
992  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
993  ereport(ERROR,
994  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
995  errmsg("bigint out of range")));
996  PG_RETURN_INT64(result);
997 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

◆ int48mul()

Datum int48mul ( PG_FUNCTION_ARGS  )

Definition at line 1000 of file int8.c.

1001 {
1002  int32 arg1 = PG_GETARG_INT32(0);
1003  int64 arg2 = PG_GETARG_INT64(1);
1004  int64 result;
1005 
1006  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1007  ereport(ERROR,
1008  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1009  errmsg("bigint out of range")));
1010  PG_RETURN_INT64(result);
1011 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

◆ int48ne()

Datum int48ne ( PG_FUNCTION_ARGS  )

Definition at line 237 of file int8.c.

238 {
239  int32 val1 = PG_GETARG_INT32(0);
240  int64 val2 = PG_GETARG_INT64(1);
241 
242  PG_RETURN_BOOL(val1 != val2);
243 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int48pl()

Datum int48pl ( PG_FUNCTION_ARGS  )

Definition at line 972 of file int8.c.

973 {
974  int32 arg1 = PG_GETARG_INT32(0);
975  int64 arg2 = PG_GETARG_INT64(1);
976  int64 result;
977 
978  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
979  ereport(ERROR,
980  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
981  errmsg("bigint out of range")));
982  PG_RETURN_INT64(result);
983 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

◆ int82()

Datum int82 ( PG_FUNCTION_ARGS  )

Definition at line 1271 of file int8.c.

1272 {
1273  int64 arg = PG_GETARG_INT64(0);
1274 
1276  ereport(ERROR,
1277  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1278  errmsg("smallint out of range")));
1279 
1281 }
#define PG_INT16_MIN
Definition: c.h:574
#define PG_INT16_MAX
Definition: c.h:575
#define PG_RETURN_INT16(x)
Definition: fmgr.h:356

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

◆ int82div()

Datum int82div ( PG_FUNCTION_ARGS  )

Definition at line 1075 of file int8.c.

1076 {
1077  int64 arg1 = PG_GETARG_INT64(0);
1078  int16 arg2 = PG_GETARG_INT16(1);
1079  int64 result;
1080 
1081  if (unlikely(arg2 == 0))
1082  {
1083  ereport(ERROR,
1084  (errcode(ERRCODE_DIVISION_BY_ZERO),
1085  errmsg("division by zero")));
1086  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1087  PG_RETURN_NULL();
1088  }
1089 
1090  /*
1091  * INT64_MIN / -1 is problematic, since the result can't be represented on
1092  * a two's-complement machine. Some machines produce INT64_MIN, some
1093  * produce zero, some throw an exception. We can dodge the problem by
1094  * recognizing that division by -1 is the same as negation.
1095  */
1096  if (arg2 == -1)
1097  {
1098  if (unlikely(arg1 == PG_INT64_MIN))
1099  ereport(ERROR,
1100  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1101  errmsg("bigint out of range")));
1102  result = -arg1;
1103  PG_RETURN_INT64(result);
1104  }
1105 
1106  /* No overflow is possible */
1107 
1108  result = arg1 / arg2;
1109 
1110  PG_RETURN_INT64(result);
1111 }
#define PG_INT64_MIN
Definition: c.h:580

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

◆ int82eq()

Datum int82eq ( PG_FUNCTION_ARGS  )

Definition at line 285 of file int8.c.

286 {
287  int64 val1 = PG_GETARG_INT64(0);
288  int16 val2 = PG_GETARG_INT16(1);
289 
290  PG_RETURN_BOOL(val1 == val2);
291 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82ge()

Datum int82ge ( PG_FUNCTION_ARGS  )

Definition at line 330 of file int8.c.

331 {
332  int64 val1 = PG_GETARG_INT64(0);
333  int16 val2 = PG_GETARG_INT16(1);
334 
335  PG_RETURN_BOOL(val1 >= val2);
336 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82gt()

Datum int82gt ( PG_FUNCTION_ARGS  )

Definition at line 312 of file int8.c.

313 {
314  int64 val1 = PG_GETARG_INT64(0);
315  int16 val2 = PG_GETARG_INT16(1);
316 
317  PG_RETURN_BOOL(val1 > val2);
318 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82le()

Datum int82le ( PG_FUNCTION_ARGS  )

Definition at line 321 of file int8.c.

322 {
323  int64 val1 = PG_GETARG_INT64(0);
324  int16 val2 = PG_GETARG_INT16(1);
325 
326  PG_RETURN_BOOL(val1 <= val2);
327 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82lt()

Datum int82lt ( PG_FUNCTION_ARGS  )

Definition at line 303 of file int8.c.

304 {
305  int64 val1 = PG_GETARG_INT64(0);
306  int16 val2 = PG_GETARG_INT16(1);
307 
308  PG_RETURN_BOOL(val1 < val2);
309 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82mi()

Datum int82mi ( PG_FUNCTION_ARGS  )

Definition at line 1047 of file int8.c.

1048 {
1049  int64 arg1 = PG_GETARG_INT64(0);
1050  int16 arg2 = PG_GETARG_INT16(1);
1051  int64 result;
1052 
1053  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
1054  ereport(ERROR,
1055  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1056  errmsg("bigint out of range")));
1057  PG_RETURN_INT64(result);
1058 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

◆ int82mul()

Datum int82mul ( PG_FUNCTION_ARGS  )

Definition at line 1061 of file int8.c.

1062 {
1063  int64 arg1 = PG_GETARG_INT64(0);
1064  int16 arg2 = PG_GETARG_INT16(1);
1065  int64 result;
1066 
1067  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
1068  ereport(ERROR,
1069  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1070  errmsg("bigint out of range")));
1071  PG_RETURN_INT64(result);
1072 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT16, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

◆ int82ne()

Datum int82ne ( PG_FUNCTION_ARGS  )

Definition at line 294 of file int8.c.

295 {
296  int64 val1 = PG_GETARG_INT64(0);
297  int16 val2 = PG_GETARG_INT16(1);
298 
299  PG_RETURN_BOOL(val1 != val2);
300 }

References PG_GETARG_INT16, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int82pl()

Datum int82pl ( PG_FUNCTION_ARGS  )

Definition at line 1033 of file int8.c.

1034 {
1035  int64 arg1 = PG_GETARG_INT64(0);
1036  int16 arg2 = PG_GETARG_INT16(1);
1037  int64 result;
1038 
1039  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
1040  ereport(ERROR,
1041  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1042  errmsg("bigint out of range")));
1043  PG_RETURN_INT64(result);
1044 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT16, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

◆ int84()

Datum int84 ( PG_FUNCTION_ARGS  )

Definition at line 1250 of file int8.c.

1251 {
1252  int64 arg = PG_GETARG_INT64(0);
1253 
1255  ereport(ERROR,
1256  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1257  errmsg("integer out of range")));
1258 
1260 }
#define PG_INT32_MAX
Definition: c.h:578
#define PG_INT32_MIN
Definition: c.h:577
#define PG_RETURN_INT32(x)
Definition: fmgr.h:354

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

Referenced by int8_to_char().

◆ int84div()

Datum int84div ( PG_FUNCTION_ARGS  )

Definition at line 933 of file int8.c.

934 {
935  int64 arg1 = PG_GETARG_INT64(0);
936  int32 arg2 = PG_GETARG_INT32(1);
937  int64 result;
938 
939  if (arg2 == 0)
940  {
941  ereport(ERROR,
942  (errcode(ERRCODE_DIVISION_BY_ZERO),
943  errmsg("division by zero")));
944  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
945  PG_RETURN_NULL();
946  }
947 
948  /*
949  * INT64_MIN / -1 is problematic, since the result can't be represented on
950  * a two's-complement machine. Some machines produce INT64_MIN, some
951  * produce zero, some throw an exception. We can dodge the problem by
952  * recognizing that division by -1 is the same as negation.
953  */
954  if (arg2 == -1)
955  {
956  if (unlikely(arg1 == PG_INT64_MIN))
957  ereport(ERROR,
958  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
959  errmsg("bigint out of range")));
960  result = -arg1;
961  PG_RETURN_INT64(result);
962  }
963 
964  /* No overflow is possible */
965 
966  result = arg1 / arg2;
967 
968  PG_RETURN_INT64(result);
969 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

◆ int84eq()

Datum int84eq ( PG_FUNCTION_ARGS  )

Definition at line 171 of file int8.c.

172 {
173  int64 val1 = PG_GETARG_INT64(0);
174  int32 val2 = PG_GETARG_INT32(1);
175 
176  PG_RETURN_BOOL(val1 == val2);
177 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84ge()

Datum int84ge ( PG_FUNCTION_ARGS  )

Definition at line 216 of file int8.c.

217 {
218  int64 val1 = PG_GETARG_INT64(0);
219  int32 val2 = PG_GETARG_INT32(1);
220 
221  PG_RETURN_BOOL(val1 >= val2);
222 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84gt()

Datum int84gt ( PG_FUNCTION_ARGS  )

Definition at line 198 of file int8.c.

199 {
200  int64 val1 = PG_GETARG_INT64(0);
201  int32 val2 = PG_GETARG_INT32(1);
202 
203  PG_RETURN_BOOL(val1 > val2);
204 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84le()

Datum int84le ( PG_FUNCTION_ARGS  )

Definition at line 207 of file int8.c.

208 {
209  int64 val1 = PG_GETARG_INT64(0);
210  int32 val2 = PG_GETARG_INT32(1);
211 
212  PG_RETURN_BOOL(val1 <= val2);
213 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84lt()

Datum int84lt ( PG_FUNCTION_ARGS  )

Definition at line 189 of file int8.c.

190 {
191  int64 val1 = PG_GETARG_INT64(0);
192  int32 val2 = PG_GETARG_INT32(1);
193 
194  PG_RETURN_BOOL(val1 < val2);
195 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84mi()

Datum int84mi ( PG_FUNCTION_ARGS  )

Definition at line 905 of file int8.c.

906 {
907  int64 arg1 = PG_GETARG_INT64(0);
908  int32 arg2 = PG_GETARG_INT32(1);
909  int64 result;
910 
911  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
912  ereport(ERROR,
913  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
914  errmsg("bigint out of range")));
915  PG_RETURN_INT64(result);
916 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

◆ int84mul()

Datum int84mul ( PG_FUNCTION_ARGS  )

Definition at line 919 of file int8.c.

920 {
921  int64 arg1 = PG_GETARG_INT64(0);
922  int32 arg2 = PG_GETARG_INT32(1);
923  int64 result;
924 
925  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
926  ereport(ERROR,
927  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
928  errmsg("bigint out of range")));
929  PG_RETURN_INT64(result);
930 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT32, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

◆ int84ne()

Datum int84ne ( PG_FUNCTION_ARGS  )

Definition at line 180 of file int8.c.

181 {
182  int64 val1 = PG_GETARG_INT64(0);
183  int32 val2 = PG_GETARG_INT32(1);
184 
185  PG_RETURN_BOOL(val1 != val2);
186 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int84pl()

Datum int84pl ( PG_FUNCTION_ARGS  )

Definition at line 891 of file int8.c.

892 {
893  int64 arg1 = PG_GETARG_INT64(0);
894  int32 arg2 = PG_GETARG_INT32(1);
895  int64 result;
896 
897  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
898  ereport(ERROR,
899  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
900  errmsg("bigint out of range")));
901  PG_RETURN_INT64(result);
902 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT32, PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

◆ int8abs()

Datum int8abs ( PG_FUNCTION_ARGS  )

Definition at line 547 of file int8.c.

548 {
549  int64 arg1 = PG_GETARG_INT64(0);
550  int64 result;
551 
552  if (unlikely(arg1 == PG_INT64_MIN))
553  ereport(ERROR,
554  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
555  errmsg("bigint out of range")));
556  result = (arg1 < 0) ? -arg1 : arg1;
557  PG_RETURN_INT64(result);
558 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, and unlikely.

◆ int8and()

Datum int8and ( PG_FUNCTION_ARGS  )

Definition at line 1185 of file int8.c.

1186 {
1187  int64 arg1 = PG_GETARG_INT64(0);
1188  int64 arg2 = PG_GETARG_INT64(1);
1189 
1190  PG_RETURN_INT64(arg1 & arg2);
1191 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8dec()

Datum int8dec ( PG_FUNCTION_ARGS  )

Definition at line 758 of file int8.c.

759 {
760  /*
761  * When int8 is pass-by-reference, we provide this special case to avoid
762  * palloc overhead for COUNT(): when called as an aggregate, we know that
763  * the argument is modifiable local storage, so just update it in-place.
764  * (If int8 is pass-by-value, then of course this is useless as well as
765  * incorrect, so just ifdef it out.)
766  */
767 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
768  if (AggCheckCallContext(fcinfo, NULL))
769  {
770  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
771 
772  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
773  ereport(ERROR,
774  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
775  errmsg("bigint out of range")));
777  }
778  else
779 #endif
780  {
781  /* Not called as an aggregate, so just do it the dumb way */
782  int64 arg = PG_GETARG_INT64(0);
783  int64 result;
784 
785  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
786  ereport(ERROR,
787  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
788  errmsg("bigint out of range")));
789 
790  PG_RETURN_INT64(result);
791  }
792 }
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4512

References AggCheckCallContext(), arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_GETARG_POINTER, PG_RETURN_INT64, PG_RETURN_POINTER, pg_sub_s64_overflow(), and unlikely.

Referenced by int8dec_any().

◆ int8dec_any()

Datum int8dec_any ( PG_FUNCTION_ARGS  )

Definition at line 817 of file int8.c.

818 {
819  return int8dec(fcinfo);
820 }
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:758

References int8dec().

◆ int8div()

Datum int8div ( PG_FUNCTION_ARGS  )

Definition at line 505 of file int8.c.

506 {
507  int64 arg1 = PG_GETARG_INT64(0);
508  int64 arg2 = PG_GETARG_INT64(1);
509  int64 result;
510 
511  if (arg2 == 0)
512  {
513  ereport(ERROR,
514  (errcode(ERRCODE_DIVISION_BY_ZERO),
515  errmsg("division by zero")));
516  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
517  PG_RETURN_NULL();
518  }
519 
520  /*
521  * INT64_MIN / -1 is problematic, since the result can't be represented on
522  * a two's-complement machine. Some machines produce INT64_MIN, some
523  * produce zero, some throw an exception. We can dodge the problem by
524  * recognizing that division by -1 is the same as negation.
525  */
526  if (arg2 == -1)
527  {
528  if (unlikely(arg1 == PG_INT64_MIN))
529  ereport(ERROR,
530  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
531  errmsg("bigint out of range")));
532  result = -arg1;
533  PG_RETURN_INT64(result);
534  }
535 
536  /* No overflow is possible */
537 
538  result = arg1 / arg2;
539 
540  PG_RETURN_INT64(result);
541 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

◆ int8eq()

Datum int8eq ( PG_FUNCTION_ARGS  )

Definition at line 114 of file int8.c.

115 {
116  int64 val1 = PG_GETARG_INT64(0);
117  int64 val2 = PG_GETARG_INT64(1);
118 
119  PG_RETURN_BOOL(val1 == val2);
120 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8gcd()

Datum int8gcd ( PG_FUNCTION_ARGS  )

Definition at line 668 of file int8.c.

669 {
670  int64 arg1 = PG_GETARG_INT64(0);
671  int64 arg2 = PG_GETARG_INT64(1);
672  int64 result;
673 
674  result = int8gcd_internal(arg1, arg2);
675 
676  PG_RETURN_INT64(result);
677 }
static int64 int8gcd_internal(int64 arg1, int64 arg2)
Definition: int8.c:607

References int8gcd_internal(), PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8gcd_internal()

static int64 int8gcd_internal ( int64  arg1,
int64  arg2 
)
static

Definition at line 607 of file int8.c.

608 {
609  int64 swap;
610  int64 a1,
611  a2;
612 
613  /*
614  * Put the greater absolute value in arg1.
615  *
616  * This would happen automatically in the loop below, but avoids an
617  * expensive modulo operation, and simplifies the special-case handling
618  * for INT64_MIN below.
619  *
620  * We do this in negative space in order to handle INT64_MIN.
621  */
622  a1 = (arg1 < 0) ? arg1 : -arg1;
623  a2 = (arg2 < 0) ? arg2 : -arg2;
624  if (a1 > a2)
625  {
626  swap = arg1;
627  arg1 = arg2;
628  arg2 = swap;
629  }
630 
631  /* Special care needs to be taken with INT64_MIN. See comments above. */
632  if (arg1 == PG_INT64_MIN)
633  {
634  if (arg2 == 0 || arg2 == PG_INT64_MIN)
635  ereport(ERROR,
636  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
637  errmsg("bigint out of range")));
638 
639  /*
640  * Some machines throw a floating-point exception for INT64_MIN % -1,
641  * which is a bit silly since the correct answer is perfectly
642  * well-defined, namely zero. Guard against this and just return the
643  * result, gcd(INT64_MIN, -1) = 1.
644  */
645  if (arg2 == -1)
646  return 1;
647  }
648 
649  /* Use the Euclidean algorithm to find the GCD */
650  while (arg2 != 0)
651  {
652  swap = arg2;
653  arg2 = arg1 % arg2;
654  arg1 = swap;
655  }
656 
657  /*
658  * Make sure the result is positive. (We know we don't have INT64_MIN
659  * anymore).
660  */
661  if (arg1 < 0)
662  arg1 = -arg1;
663 
664  return arg1;
665 }
static const FormData_pg_attribute a1
Definition: heap.c:141
static const FormData_pg_attribute a2
Definition: heap.c:155

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

Referenced by int8gcd(), and int8lcm().

◆ int8ge()

Datum int8ge ( PG_FUNCTION_ARGS  )

Definition at line 159 of file int8.c.

160 {
161  int64 val1 = PG_GETARG_INT64(0);
162  int64 val2 = PG_GETARG_INT64(1);
163 
164  PG_RETURN_BOOL(val1 >= val2);
165 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8gt()

Datum int8gt ( PG_FUNCTION_ARGS  )

Definition at line 141 of file int8.c.

142 {
143  int64 val1 = PG_GETARG_INT64(0);
144  int64 val2 = PG_GETARG_INT64(1);
145 
146  PG_RETURN_BOOL(val1 > val2);
147 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8in()

Datum int8in ( PG_FUNCTION_ARGS  )

Definition at line 51 of file int8.c.

52 {
53  char *num = PG_GETARG_CSTRING(0);
54 
55  PG_RETURN_INT64(pg_strtoint64_safe(num, fcinfo->context));
56 }
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:277
int64 pg_strtoint64_safe(const char *s, Node *escontext)
Definition: numutils.c:652

References PG_GETARG_CSTRING, PG_RETURN_INT64, and pg_strtoint64_safe().

Referenced by defGetInt64().

◆ int8inc()

Datum int8inc ( PG_FUNCTION_ARGS  )

Definition at line 720 of file int8.c.

721 {
722  /*
723  * When int8 is pass-by-reference, we provide this special case to avoid
724  * palloc overhead for COUNT(): when called as an aggregate, we know that
725  * the argument is modifiable local storage, so just update it in-place.
726  * (If int8 is pass-by-value, then of course this is useless as well as
727  * incorrect, so just ifdef it out.)
728  */
729 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
730  if (AggCheckCallContext(fcinfo, NULL))
731  {
732  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
733 
734  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
735  ereport(ERROR,
736  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
737  errmsg("bigint out of range")));
738 
740  }
741  else
742 #endif
743  {
744  /* Not called as an aggregate, so just do it the dumb way */
745  int64 arg = PG_GETARG_INT64(0);
746  int64 result;
747 
748  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
749  ereport(ERROR,
750  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
751  errmsg("bigint out of range")));
752 
753  PG_RETURN_INT64(result);
754  }
755 }

References AggCheckCallContext(), arg, ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT64, PG_GETARG_POINTER, PG_RETURN_INT64, PG_RETURN_POINTER, and unlikely.

Referenced by int8inc_any(), and int8inc_float8_float8().

◆ int8inc_any()

Datum int8inc_any ( PG_FUNCTION_ARGS  )

Definition at line 805 of file int8.c.

806 {
807  return int8inc(fcinfo);
808 }
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:720

References int8inc().

◆ int8inc_float8_float8()

Datum int8inc_float8_float8 ( PG_FUNCTION_ARGS  )

Definition at line 811 of file int8.c.

812 {
813  return int8inc(fcinfo);
814 }

References int8inc().

◆ int8inc_support()

Datum int8inc_support ( PG_FUNCTION_ARGS  )

Definition at line 827 of file int8.c.

828 {
829  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
830 
831  if (IsA(rawreq, SupportRequestWFuncMonotonic))
832  {
835  int frameOptions = req->window_clause->frameOptions;
836 
837  /* No ORDER BY clause then all rows are peers */
838  if (req->window_clause->orderClause == NIL)
839  monotonic = MONOTONICFUNC_BOTH;
840  else
841  {
842  /*
843  * Otherwise take into account the frame options. When the frame
844  * bound is the start of the window then the resulting value can
845  * never decrease, therefore is monotonically increasing
846  */
847  if (frameOptions & FRAMEOPTION_START_UNBOUNDED_PRECEDING)
848  monotonic |= MONOTONICFUNC_INCREASING;
849 
850  /*
851  * Likewise, if the frame bound is the end of the window then the
852  * resulting value can never decrease.
853  */
854  if (frameOptions & FRAMEOPTION_END_UNBOUNDED_FOLLOWING)
855  monotonic |= MONOTONICFUNC_DECREASING;
856  }
857 
858  req->monotonic = monotonic;
859  PG_RETURN_POINTER(req);
860  }
861 
862  PG_RETURN_POINTER(NULL);
863 }
#define FRAMEOPTION_START_UNBOUNDED_PRECEDING
Definition: parsenodes.h:583
#define FRAMEOPTION_END_UNBOUNDED_FOLLOWING
Definition: parsenodes.h:586
#define NIL
Definition: pg_list.h:68
MonotonicFunction
Definition: plannodes.h:1584
@ MONOTONICFUNC_NONE
Definition: plannodes.h:1585
@ MONOTONICFUNC_DECREASING
Definition: plannodes.h:1587
@ MONOTONICFUNC_INCREASING
Definition: plannodes.h:1586
@ MONOTONICFUNC_BOTH
Definition: plannodes.h:1588
struct WindowClause * window_clause
Definition: supportnodes.h:296
MonotonicFunction monotonic
Definition: supportnodes.h:299
List * orderClause
Definition: parsenodes.h:1498

References FRAMEOPTION_END_UNBOUNDED_FOLLOWING, FRAMEOPTION_START_UNBOUNDED_PRECEDING, WindowClause::frameOptions, IsA, SupportRequestWFuncMonotonic::monotonic, MONOTONICFUNC_BOTH, MONOTONICFUNC_DECREASING, MONOTONICFUNC_INCREASING, MONOTONICFUNC_NONE, NIL, WindowClause::orderClause, PG_GETARG_POINTER, PG_RETURN_POINTER, and SupportRequestWFuncMonotonic::window_clause.

◆ int8larger()

Datum int8larger ( PG_FUNCTION_ARGS  )

Definition at line 867 of file int8.c.

868 {
869  int64 arg1 = PG_GETARG_INT64(0);
870  int64 arg2 = PG_GETARG_INT64(1);
871  int64 result;
872 
873  result = ((arg1 > arg2) ? arg1 : arg2);
874 
875  PG_RETURN_INT64(result);
876 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8lcm()

Datum int8lcm ( PG_FUNCTION_ARGS  )

Definition at line 683 of file int8.c.

684 {
685  int64 arg1 = PG_GETARG_INT64(0);
686  int64 arg2 = PG_GETARG_INT64(1);
687  int64 gcd;
688  int64 result;
689 
690  /*
691  * Handle lcm(x, 0) = lcm(0, x) = 0 as a special case. This prevents a
692  * division-by-zero error below when x is zero, and an overflow error from
693  * the GCD computation when x = INT64_MIN.
694  */
695  if (arg1 == 0 || arg2 == 0)
696  PG_RETURN_INT64(0);
697 
698  /* lcm(x, y) = abs(x / gcd(x, y) * y) */
699  gcd = int8gcd_internal(arg1, arg2);
700  arg1 = arg1 / gcd;
701 
702  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
703  ereport(ERROR,
704  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
705  errmsg("bigint out of range")));
706 
707  /* If the result is INT64_MIN, it cannot be represented. */
708  if (unlikely(result == PG_INT64_MIN))
709  ereport(ERROR,
710  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
711  errmsg("bigint out of range")));
712 
713  if (result < 0)
714  result = -result;
715 
716  PG_RETURN_INT64(result);
717 }
static uint32 gcd(uint32 a, uint32 b)

References ereport, errcode(), errmsg(), ERROR, gcd(), int8gcd_internal(), PG_GETARG_INT64, PG_INT64_MIN, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

◆ int8le()

Datum int8le ( PG_FUNCTION_ARGS  )

Definition at line 150 of file int8.c.

151 {
152  int64 val1 = PG_GETARG_INT64(0);
153  int64 val2 = PG_GETARG_INT64(1);
154 
155  PG_RETURN_BOOL(val1 <= val2);
156 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8lt()

Datum int8lt ( PG_FUNCTION_ARGS  )

Definition at line 132 of file int8.c.

133 {
134  int64 val1 = PG_GETARG_INT64(0);
135  int64 val2 = PG_GETARG_INT64(1);
136 
137  PG_RETURN_BOOL(val1 < val2);
138 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8mi()

Datum int8mi ( PG_FUNCTION_ARGS  )

Definition at line 477 of file int8.c.

478 {
479  int64 arg1 = PG_GETARG_INT64(0);
480  int64 arg2 = PG_GETARG_INT64(1);
481  int64 result;
482 
483  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
484  ereport(ERROR,
485  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
486  errmsg("bigint out of range")));
487  PG_RETURN_INT64(result);
488 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_INT64, pg_sub_s64_overflow(), and unlikely.

◆ int8mod()

Datum int8mod ( PG_FUNCTION_ARGS  )

Definition at line 564 of file int8.c.

565 {
566  int64 arg1 = PG_GETARG_INT64(0);
567  int64 arg2 = PG_GETARG_INT64(1);
568 
569  if (unlikely(arg2 == 0))
570  {
571  ereport(ERROR,
572  (errcode(ERRCODE_DIVISION_BY_ZERO),
573  errmsg("division by zero")));
574  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
575  PG_RETURN_NULL();
576  }
577 
578  /*
579  * Some machines throw a floating-point exception for INT64_MIN % -1,
580  * which is a bit silly since the correct answer is perfectly
581  * well-defined, namely zero.
582  */
583  if (arg2 == -1)
584  PG_RETURN_INT64(0);
585 
586  /* No overflow is possible */
587 
588  PG_RETURN_INT64(arg1 % arg2);
589 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_RETURN_INT64, PG_RETURN_NULL, and unlikely.

◆ int8mul()

Datum int8mul ( PG_FUNCTION_ARGS  )

Definition at line 491 of file int8.c.

492 {
493  int64 arg1 = PG_GETARG_INT64(0);
494  int64 arg2 = PG_GETARG_INT64(1);
495  int64 result;
496 
497  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
498  ereport(ERROR,
499  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
500  errmsg("bigint out of range")));
501  PG_RETURN_INT64(result);
502 }

References ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, pg_mul_s64_overflow(), PG_RETURN_INT64, and unlikely.

Referenced by int4_cash(), int8_cash(), and int8_to_char().

◆ int8ne()

Datum int8ne ( PG_FUNCTION_ARGS  )

Definition at line 123 of file int8.c.

124 {
125  int64 val1 = PG_GETARG_INT64(0);
126  int64 val2 = PG_GETARG_INT64(1);
127 
128  PG_RETURN_BOOL(val1 != val2);
129 }

References PG_GETARG_INT64, and PG_RETURN_BOOL.

◆ int8not()

Datum int8not ( PG_FUNCTION_ARGS  )

Definition at line 1212 of file int8.c.

1213 {
1214  int64 arg1 = PG_GETARG_INT64(0);
1215 
1216  PG_RETURN_INT64(~arg1);
1217 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8or()

Datum int8or ( PG_FUNCTION_ARGS  )

Definition at line 1194 of file int8.c.

1195 {
1196  int64 arg1 = PG_GETARG_INT64(0);
1197  int64 arg2 = PG_GETARG_INT64(1);
1198 
1199  PG_RETURN_INT64(arg1 | arg2);
1200 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8out()

Datum int8out ( PG_FUNCTION_ARGS  )

Definition at line 62 of file int8.c.

63 {
64  int64 val = PG_GETARG_INT64(0);
65  char buf[MAXINT8LEN + 1];
66  char *result;
67  int len;
68 
69  len = pg_lltoa(val, buf) + 1;
70 
71  /*
72  * Since the length is already known, we do a manual palloc() and memcpy()
73  * to avoid the strlen() call that would otherwise be done in pstrdup().
74  */
75  result = palloc(len);
76  memcpy(result, buf, len);
77  PG_RETURN_CSTRING(result);
78 }
#define MAXINT8LEN
Definition: builtins.h:22
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:362
int pg_lltoa(int64 value, char *a)
Definition: numutils.c:1230
const void size_t len
static char * buf
Definition: pg_test_fsync.c:67

References buf, len, MAXINT8LEN, palloc(), PG_GETARG_INT64, pg_lltoa(), PG_RETURN_CSTRING, and val.

Referenced by int8_to_char().

◆ int8pl()

Datum int8pl ( PG_FUNCTION_ARGS  )

Definition at line 463 of file int8.c.

464 {
465  int64 arg1 = PG_GETARG_INT64(0);
466  int64 arg2 = PG_GETARG_INT64(1);
467  int64 result;
468 
469  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
470  ereport(ERROR,
471  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
472  errmsg("bigint out of range")));
473  PG_RETURN_INT64(result);
474 }

References ereport, errcode(), errmsg(), ERROR, pg_add_s64_overflow(), PG_GETARG_INT64, PG_RETURN_INT64, and unlikely.

◆ int8recv()

Datum int8recv ( PG_FUNCTION_ARGS  )

Definition at line 84 of file int8.c.

85 {
87 
89 }
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:456
StringInfoData * StringInfo
Definition: stringinfo.h:44

References buf, PG_GETARG_POINTER, PG_RETURN_INT64, and pq_getmsgint64().

◆ int8send()

Datum int8send ( PG_FUNCTION_ARGS  )

Definition at line 95 of file int8.c.

96 {
97  int64 arg1 = PG_GETARG_INT64(0);
99 
101  pq_sendint64(&buf, arg1);
103 }
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:371
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:329
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:349
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153

References buf, PG_GETARG_INT64, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendint64().

◆ int8shl()

Datum int8shl ( PG_FUNCTION_ARGS  )

Definition at line 1220 of file int8.c.

1221 {
1222  int64 arg1 = PG_GETARG_INT64(0);
1223  int32 arg2 = PG_GETARG_INT32(1);
1224 
1225  PG_RETURN_INT64(arg1 << arg2);
1226 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8shr()

Datum int8shr ( PG_FUNCTION_ARGS  )

Definition at line 1229 of file int8.c.

1230 {
1231  int64 arg1 = PG_GETARG_INT64(0);
1232  int32 arg2 = PG_GETARG_INT32(1);
1233 
1234  PG_RETURN_INT64(arg1 >> arg2);
1235 }

References PG_GETARG_INT32, PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8smaller()

Datum int8smaller ( PG_FUNCTION_ARGS  )

Definition at line 879 of file int8.c.

880 {
881  int64 arg1 = PG_GETARG_INT64(0);
882  int64 arg2 = PG_GETARG_INT64(1);
883  int64 result;
884 
885  result = ((arg1 < arg2) ? arg1 : arg2);
886 
887  PG_RETURN_INT64(result);
888 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8um()

Datum int8um ( PG_FUNCTION_ARGS  )

Definition at line 441 of file int8.c.

442 {
443  int64 arg = PG_GETARG_INT64(0);
444  int64 result;
445 
446  if (unlikely(arg == PG_INT64_MIN))
447  ereport(ERROR,
448  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
449  errmsg("bigint out of range")));
450  result = -arg;
451  PG_RETURN_INT64(result);
452 }

References arg, ereport, errcode(), errmsg(), ERROR, PG_GETARG_INT64, PG_INT64_MIN, PG_RETURN_INT64, and unlikely.

◆ int8up()

Datum int8up ( PG_FUNCTION_ARGS  )

Definition at line 455 of file int8.c.

456 {
457  int64 arg = PG_GETARG_INT64(0);
458 
460 }

References arg, PG_GETARG_INT64, and PG_RETURN_INT64.

◆ int8xor()

Datum int8xor ( PG_FUNCTION_ARGS  )

Definition at line 1203 of file int8.c.

1204 {
1205  int64 arg1 = PG_GETARG_INT64(0);
1206  int64 arg2 = PG_GETARG_INT64(1);
1207 
1208  PG_RETURN_INT64(arg1 ^ arg2);
1209 }

References PG_GETARG_INT64, and PG_RETURN_INT64.

◆ oidtoi8()

Datum oidtoi8 ( PG_FUNCTION_ARGS  )

Definition at line 1367 of file int8.c.

1368 {
1369  Oid arg = PG_GETARG_OID(0);
1370 
1371  PG_RETURN_INT64((int64) arg);
1372 }
#define PG_GETARG_OID(n)
Definition: fmgr.h:275

References arg, PG_GETARG_OID, and PG_RETURN_INT64.