PostgreSQL Source Code  git master
int8.c
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2  *
3  * int8.c
4  * Internal 64-bit integer operations
5  *
6  * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group
7  * Portions Copyright (c) 1994, Regents of the University of California
8  *
9  * IDENTIFICATION
10  * src/backend/utils/adt/int8.c
11  *
12  *-------------------------------------------------------------------------
13  */
14 #include "postgres.h"
15 
16 #include <ctype.h>
17 #include <limits.h>
18 #include <math.h>
19 
20 #include "common/int.h"
21 #include "funcapi.h"
22 #include "libpq/pqformat.h"
23 #include "nodes/nodeFuncs.h"
24 #include "nodes/supportnodes.h"
25 #include "optimizer/optimizer.h"
26 #include "utils/builtins.h"
27 #include "utils/int8.h"
28 
29 #define MAXINT8LEN 25
30 
31 typedef struct
32 {
33  int64 current;
34  int64 finish;
35  int64 step;
37 
38 
39 /***********************************************************************
40  **
41  ** Routines for 64-bit integers.
42  **
43  ***********************************************************************/
44 
45 /*----------------------------------------------------------
46  * Formatting and conversion routines.
47  *---------------------------------------------------------*/
48 
49 /*
50  * scanint8 --- try to parse a string into an int8.
51  *
52  * If errorOK is false, ereport a useful error message if the string is bad.
53  * If errorOK is true, just return "false" for bad input.
54  */
55 bool
56 scanint8(const char *str, bool errorOK, int64 *result)
57 {
58  const char *ptr = str;
59  int64 tmp = 0;
60  bool neg = false;
61 
62  /*
63  * Do our own scan, rather than relying on sscanf which might be broken
64  * for long long.
65  *
66  * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
67  * value as a negative number.
68  */
69 
70  /* skip leading spaces */
71  while (*ptr && isspace((unsigned char) *ptr))
72  ptr++;
73 
74  /* handle sign */
75  if (*ptr == '-')
76  {
77  ptr++;
78  neg = true;
79  }
80  else if (*ptr == '+')
81  ptr++;
82 
83  /* require at least one digit */
84  if (unlikely(!isdigit((unsigned char) *ptr)))
85  goto invalid_syntax;
86 
87  /* process digits */
88  while (*ptr && isdigit((unsigned char) *ptr))
89  {
90  int8 digit = (*ptr++ - '0');
91 
92  if (unlikely(pg_mul_s64_overflow(tmp, 10, &tmp)) ||
93  unlikely(pg_sub_s64_overflow(tmp, digit, &tmp)))
94  goto out_of_range;
95  }
96 
97  /* allow trailing whitespace, but not other trailing chars */
98  while (*ptr != '\0' && isspace((unsigned char) *ptr))
99  ptr++;
100 
101  if (unlikely(*ptr != '\0'))
102  goto invalid_syntax;
103 
104  if (!neg)
105  {
106  /* could fail if input is most negative number */
107  if (unlikely(tmp == PG_INT64_MIN))
108  goto out_of_range;
109  tmp = -tmp;
110  }
111 
112  *result = tmp;
113  return true;
114 
115 out_of_range:
116  if (!errorOK)
117  ereport(ERROR,
118  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
119  errmsg("value \"%s\" is out of range for type %s",
120  str, "bigint")));
121  return false;
122 
123 invalid_syntax:
124  if (!errorOK)
125  ereport(ERROR,
126  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
127  errmsg("invalid input syntax for type %s: \"%s\"",
128  "bigint", str)));
129  return false;
130 }
131 
132 /* int8in()
133  */
134 Datum
136 {
137  char *str = PG_GETARG_CSTRING(0);
138  int64 result;
139 
140  (void) scanint8(str, false, &result);
141  PG_RETURN_INT64(result);
142 }
143 
144 
145 /* int8out()
146  */
147 Datum
149 {
150  int64 val = PG_GETARG_INT64(0);
151  char buf[MAXINT8LEN + 1];
152  char *result;
153 
154  pg_lltoa(val, buf);
155  result = pstrdup(buf);
156  PG_RETURN_CSTRING(result);
157 }
158 
159 /*
160  * int8recv - converts external binary format to int8
161  */
162 Datum
164 {
166 
168 }
169 
170 /*
171  * int8send - converts int8 to binary format
172  */
173 Datum
175 {
176  int64 arg1 = PG_GETARG_INT64(0);
178 
179  pq_begintypsend(&buf);
180  pq_sendint64(&buf, arg1);
182 }
183 
184 
185 /*----------------------------------------------------------
186  * Relational operators for int8s, including cross-data-type comparisons.
187  *---------------------------------------------------------*/
188 
189 /* int8relop()
190  * Is val1 relop val2?
191  */
192 Datum
194 {
195  int64 val1 = PG_GETARG_INT64(0);
196  int64 val2 = PG_GETARG_INT64(1);
197 
198  PG_RETURN_BOOL(val1 == val2);
199 }
200 
201 Datum
203 {
204  int64 val1 = PG_GETARG_INT64(0);
205  int64 val2 = PG_GETARG_INT64(1);
206 
207  PG_RETURN_BOOL(val1 != val2);
208 }
209 
210 Datum
212 {
213  int64 val1 = PG_GETARG_INT64(0);
214  int64 val2 = PG_GETARG_INT64(1);
215 
216  PG_RETURN_BOOL(val1 < val2);
217 }
218 
219 Datum
221 {
222  int64 val1 = PG_GETARG_INT64(0);
223  int64 val2 = PG_GETARG_INT64(1);
224 
225  PG_RETURN_BOOL(val1 > val2);
226 }
227 
228 Datum
230 {
231  int64 val1 = PG_GETARG_INT64(0);
232  int64 val2 = PG_GETARG_INT64(1);
233 
234  PG_RETURN_BOOL(val1 <= val2);
235 }
236 
237 Datum
239 {
240  int64 val1 = PG_GETARG_INT64(0);
241  int64 val2 = PG_GETARG_INT64(1);
242 
243  PG_RETURN_BOOL(val1 >= val2);
244 }
245 
246 /* int84relop()
247  * Is 64-bit val1 relop 32-bit val2?
248  */
249 Datum
251 {
252  int64 val1 = PG_GETARG_INT64(0);
253  int32 val2 = PG_GETARG_INT32(1);
254 
255  PG_RETURN_BOOL(val1 == val2);
256 }
257 
258 Datum
260 {
261  int64 val1 = PG_GETARG_INT64(0);
262  int32 val2 = PG_GETARG_INT32(1);
263 
264  PG_RETURN_BOOL(val1 != val2);
265 }
266 
267 Datum
269 {
270  int64 val1 = PG_GETARG_INT64(0);
271  int32 val2 = PG_GETARG_INT32(1);
272 
273  PG_RETURN_BOOL(val1 < val2);
274 }
275 
276 Datum
278 {
279  int64 val1 = PG_GETARG_INT64(0);
280  int32 val2 = PG_GETARG_INT32(1);
281 
282  PG_RETURN_BOOL(val1 > val2);
283 }
284 
285 Datum
287 {
288  int64 val1 = PG_GETARG_INT64(0);
289  int32 val2 = PG_GETARG_INT32(1);
290 
291  PG_RETURN_BOOL(val1 <= val2);
292 }
293 
294 Datum
296 {
297  int64 val1 = PG_GETARG_INT64(0);
298  int32 val2 = PG_GETARG_INT32(1);
299 
300  PG_RETURN_BOOL(val1 >= val2);
301 }
302 
303 /* int48relop()
304  * Is 32-bit val1 relop 64-bit val2?
305  */
306 Datum
308 {
309  int32 val1 = PG_GETARG_INT32(0);
310  int64 val2 = PG_GETARG_INT64(1);
311 
312  PG_RETURN_BOOL(val1 == val2);
313 }
314 
315 Datum
317 {
318  int32 val1 = PG_GETARG_INT32(0);
319  int64 val2 = PG_GETARG_INT64(1);
320 
321  PG_RETURN_BOOL(val1 != val2);
322 }
323 
324 Datum
326 {
327  int32 val1 = PG_GETARG_INT32(0);
328  int64 val2 = PG_GETARG_INT64(1);
329 
330  PG_RETURN_BOOL(val1 < val2);
331 }
332 
333 Datum
335 {
336  int32 val1 = PG_GETARG_INT32(0);
337  int64 val2 = PG_GETARG_INT64(1);
338 
339  PG_RETURN_BOOL(val1 > val2);
340 }
341 
342 Datum
344 {
345  int32 val1 = PG_GETARG_INT32(0);
346  int64 val2 = PG_GETARG_INT64(1);
347 
348  PG_RETURN_BOOL(val1 <= val2);
349 }
350 
351 Datum
353 {
354  int32 val1 = PG_GETARG_INT32(0);
355  int64 val2 = PG_GETARG_INT64(1);
356 
357  PG_RETURN_BOOL(val1 >= val2);
358 }
359 
360 /* int82relop()
361  * Is 64-bit val1 relop 16-bit val2?
362  */
363 Datum
365 {
366  int64 val1 = PG_GETARG_INT64(0);
367  int16 val2 = PG_GETARG_INT16(1);
368 
369  PG_RETURN_BOOL(val1 == val2);
370 }
371 
372 Datum
374 {
375  int64 val1 = PG_GETARG_INT64(0);
376  int16 val2 = PG_GETARG_INT16(1);
377 
378  PG_RETURN_BOOL(val1 != val2);
379 }
380 
381 Datum
383 {
384  int64 val1 = PG_GETARG_INT64(0);
385  int16 val2 = PG_GETARG_INT16(1);
386 
387  PG_RETURN_BOOL(val1 < val2);
388 }
389 
390 Datum
392 {
393  int64 val1 = PG_GETARG_INT64(0);
394  int16 val2 = PG_GETARG_INT16(1);
395 
396  PG_RETURN_BOOL(val1 > val2);
397 }
398 
399 Datum
401 {
402  int64 val1 = PG_GETARG_INT64(0);
403  int16 val2 = PG_GETARG_INT16(1);
404 
405  PG_RETURN_BOOL(val1 <= val2);
406 }
407 
408 Datum
410 {
411  int64 val1 = PG_GETARG_INT64(0);
412  int16 val2 = PG_GETARG_INT16(1);
413 
414  PG_RETURN_BOOL(val1 >= val2);
415 }
416 
417 /* int28relop()
418  * Is 16-bit val1 relop 64-bit val2?
419  */
420 Datum
422 {
423  int16 val1 = PG_GETARG_INT16(0);
424  int64 val2 = PG_GETARG_INT64(1);
425 
426  PG_RETURN_BOOL(val1 == val2);
427 }
428 
429 Datum
431 {
432  int16 val1 = PG_GETARG_INT16(0);
433  int64 val2 = PG_GETARG_INT64(1);
434 
435  PG_RETURN_BOOL(val1 != val2);
436 }
437 
438 Datum
440 {
441  int16 val1 = PG_GETARG_INT16(0);
442  int64 val2 = PG_GETARG_INT64(1);
443 
444  PG_RETURN_BOOL(val1 < val2);
445 }
446 
447 Datum
449 {
450  int16 val1 = PG_GETARG_INT16(0);
451  int64 val2 = PG_GETARG_INT64(1);
452 
453  PG_RETURN_BOOL(val1 > val2);
454 }
455 
456 Datum
458 {
459  int16 val1 = PG_GETARG_INT16(0);
460  int64 val2 = PG_GETARG_INT64(1);
461 
462  PG_RETURN_BOOL(val1 <= val2);
463 }
464 
465 Datum
467 {
468  int16 val1 = PG_GETARG_INT16(0);
469  int64 val2 = PG_GETARG_INT64(1);
470 
471  PG_RETURN_BOOL(val1 >= val2);
472 }
473 
474 /*
475  * in_range support function for int8.
476  *
477  * Note: we needn't supply int8_int4 or int8_int2 variants, as implicit
478  * coercion of the offset value takes care of those scenarios just as well.
479  */
480 Datum
482 {
483  int64 val = PG_GETARG_INT64(0);
484  int64 base = PG_GETARG_INT64(1);
485  int64 offset = PG_GETARG_INT64(2);
486  bool sub = PG_GETARG_BOOL(3);
487  bool less = PG_GETARG_BOOL(4);
488  int64 sum;
489 
490  if (offset < 0)
491  ereport(ERROR,
492  (errcode(ERRCODE_INVALID_PRECEDING_OR_FOLLOWING_SIZE),
493  errmsg("invalid preceding or following size in window function")));
494 
495  if (sub)
496  offset = -offset; /* cannot overflow */
497 
498  if (unlikely(pg_add_s64_overflow(base, offset, &sum)))
499  {
500  /*
501  * If sub is false, the true sum is surely more than val, so correct
502  * answer is the same as "less". If sub is true, the true sum is
503  * surely less than val, so the answer is "!less".
504  */
505  PG_RETURN_BOOL(sub ? !less : less);
506  }
507 
508  if (less)
509  PG_RETURN_BOOL(val <= sum);
510  else
511  PG_RETURN_BOOL(val >= sum);
512 }
513 
514 
515 /*----------------------------------------------------------
516  * Arithmetic operators on 64-bit integers.
517  *---------------------------------------------------------*/
518 
519 Datum
521 {
522  int64 arg = PG_GETARG_INT64(0);
523  int64 result;
524 
525  if (unlikely(arg == PG_INT64_MIN))
526  ereport(ERROR,
527  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
528  errmsg("bigint out of range")));
529  result = -arg;
530  PG_RETURN_INT64(result);
531 }
532 
533 Datum
535 {
536  int64 arg = PG_GETARG_INT64(0);
537 
538  PG_RETURN_INT64(arg);
539 }
540 
541 Datum
543 {
544  int64 arg1 = PG_GETARG_INT64(0);
545  int64 arg2 = PG_GETARG_INT64(1);
546  int64 result;
547 
548  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
549  ereport(ERROR,
550  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
551  errmsg("bigint out of range")));
552  PG_RETURN_INT64(result);
553 }
554 
555 Datum
557 {
558  int64 arg1 = PG_GETARG_INT64(0);
559  int64 arg2 = PG_GETARG_INT64(1);
560  int64 result;
561 
562  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
563  ereport(ERROR,
564  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
565  errmsg("bigint out of range")));
566  PG_RETURN_INT64(result);
567 }
568 
569 Datum
571 {
572  int64 arg1 = PG_GETARG_INT64(0);
573  int64 arg2 = PG_GETARG_INT64(1);
574  int64 result;
575 
576  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
577  ereport(ERROR,
578  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
579  errmsg("bigint out of range")));
580  PG_RETURN_INT64(result);
581 }
582 
583 Datum
585 {
586  int64 arg1 = PG_GETARG_INT64(0);
587  int64 arg2 = PG_GETARG_INT64(1);
588  int64 result;
589 
590  if (arg2 == 0)
591  {
592  ereport(ERROR,
593  (errcode(ERRCODE_DIVISION_BY_ZERO),
594  errmsg("division by zero")));
595  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
596  PG_RETURN_NULL();
597  }
598 
599  /*
600  * INT64_MIN / -1 is problematic, since the result can't be represented on
601  * a two's-complement machine. Some machines produce INT64_MIN, some
602  * produce zero, some throw an exception. We can dodge the problem by
603  * recognizing that division by -1 is the same as negation.
604  */
605  if (arg2 == -1)
606  {
607  if (unlikely(arg1 == PG_INT64_MIN))
608  ereport(ERROR,
609  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
610  errmsg("bigint out of range")));
611  result = -arg1;
612  PG_RETURN_INT64(result);
613  }
614 
615  /* No overflow is possible */
616 
617  result = arg1 / arg2;
618 
619  PG_RETURN_INT64(result);
620 }
621 
622 /* int8abs()
623  * Absolute value
624  */
625 Datum
627 {
628  int64 arg1 = PG_GETARG_INT64(0);
629  int64 result;
630 
631  if (unlikely(arg1 == PG_INT64_MIN))
632  ereport(ERROR,
633  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
634  errmsg("bigint out of range")));
635  result = (arg1 < 0) ? -arg1 : arg1;
636  PG_RETURN_INT64(result);
637 }
638 
639 /* int8mod()
640  * Modulo operation.
641  */
642 Datum
644 {
645  int64 arg1 = PG_GETARG_INT64(0);
646  int64 arg2 = PG_GETARG_INT64(1);
647 
648  if (unlikely(arg2 == 0))
649  {
650  ereport(ERROR,
651  (errcode(ERRCODE_DIVISION_BY_ZERO),
652  errmsg("division by zero")));
653  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
654  PG_RETURN_NULL();
655  }
656 
657  /*
658  * Some machines throw a floating-point exception for INT64_MIN % -1,
659  * which is a bit silly since the correct answer is perfectly
660  * well-defined, namely zero.
661  */
662  if (arg2 == -1)
663  PG_RETURN_INT64(0);
664 
665  /* No overflow is possible */
666 
667  PG_RETURN_INT64(arg1 % arg2);
668 }
669 
670 
671 Datum
673 {
674  /*
675  * When int8 is pass-by-reference, we provide this special case to avoid
676  * palloc overhead for COUNT(): when called as an aggregate, we know that
677  * the argument is modifiable local storage, so just update it in-place.
678  * (If int8 is pass-by-value, then of course this is useless as well as
679  * incorrect, so just ifdef it out.)
680  */
681 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
682  if (AggCheckCallContext(fcinfo, NULL))
683  {
684  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
685 
686  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
687  ereport(ERROR,
688  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
689  errmsg("bigint out of range")));
690 
691  PG_RETURN_POINTER(arg);
692  }
693  else
694 #endif
695  {
696  /* Not called as an aggregate, so just do it the dumb way */
697  int64 arg = PG_GETARG_INT64(0);
698  int64 result;
699 
700  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
701  ereport(ERROR,
702  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
703  errmsg("bigint out of range")));
704 
705  PG_RETURN_INT64(result);
706  }
707 }
708 
709 Datum
711 {
712  /*
713  * When int8 is pass-by-reference, we provide this special case to avoid
714  * palloc overhead for COUNT(): when called as an aggregate, we know that
715  * the argument is modifiable local storage, so just update it in-place.
716  * (If int8 is pass-by-value, then of course this is useless as well as
717  * incorrect, so just ifdef it out.)
718  */
719 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
720  if (AggCheckCallContext(fcinfo, NULL))
721  {
722  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
723 
724  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
725  ereport(ERROR,
726  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
727  errmsg("bigint out of range")));
728  PG_RETURN_POINTER(arg);
729  }
730  else
731 #endif
732  {
733  /* Not called as an aggregate, so just do it the dumb way */
734  int64 arg = PG_GETARG_INT64(0);
735  int64 result;
736 
737  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
738  ereport(ERROR,
739  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
740  errmsg("bigint out of range")));
741 
742  PG_RETURN_INT64(result);
743  }
744 }
745 
746 
747 /*
748  * These functions are exactly like int8inc/int8dec but are used for
749  * aggregates that count only non-null values. Since the functions are
750  * declared strict, the null checks happen before we ever get here, and all we
751  * need do is increment the state value. We could actually make these pg_proc
752  * entries point right at int8inc/int8dec, but then the opr_sanity regression
753  * test would complain about mismatched entries for a built-in function.
754  */
755 
756 Datum
758 {
759  return int8inc(fcinfo);
760 }
761 
762 Datum
764 {
765  return int8inc(fcinfo);
766 }
767 
768 Datum
770 {
771  return int8dec(fcinfo);
772 }
773 
774 
775 Datum
777 {
778  int64 arg1 = PG_GETARG_INT64(0);
779  int64 arg2 = PG_GETARG_INT64(1);
780  int64 result;
781 
782  result = ((arg1 > arg2) ? arg1 : arg2);
783 
784  PG_RETURN_INT64(result);
785 }
786 
787 Datum
789 {
790  int64 arg1 = PG_GETARG_INT64(0);
791  int64 arg2 = PG_GETARG_INT64(1);
792  int64 result;
793 
794  result = ((arg1 < arg2) ? arg1 : arg2);
795 
796  PG_RETURN_INT64(result);
797 }
798 
799 Datum
801 {
802  int64 arg1 = PG_GETARG_INT64(0);
803  int32 arg2 = PG_GETARG_INT32(1);
804  int64 result;
805 
806  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
807  ereport(ERROR,
808  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
809  errmsg("bigint out of range")));
810  PG_RETURN_INT64(result);
811 }
812 
813 Datum
815 {
816  int64 arg1 = PG_GETARG_INT64(0);
817  int32 arg2 = PG_GETARG_INT32(1);
818  int64 result;
819 
820  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
821  ereport(ERROR,
822  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
823  errmsg("bigint out of range")));
824  PG_RETURN_INT64(result);
825 }
826 
827 Datum
829 {
830  int64 arg1 = PG_GETARG_INT64(0);
831  int32 arg2 = PG_GETARG_INT32(1);
832  int64 result;
833 
834  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
835  ereport(ERROR,
836  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
837  errmsg("bigint out of range")));
838  PG_RETURN_INT64(result);
839 }
840 
841 Datum
843 {
844  int64 arg1 = PG_GETARG_INT64(0);
845  int32 arg2 = PG_GETARG_INT32(1);
846  int64 result;
847 
848  if (arg2 == 0)
849  {
850  ereport(ERROR,
851  (errcode(ERRCODE_DIVISION_BY_ZERO),
852  errmsg("division by zero")));
853  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
854  PG_RETURN_NULL();
855  }
856 
857  /*
858  * INT64_MIN / -1 is problematic, since the result can't be represented on
859  * a two's-complement machine. Some machines produce INT64_MIN, some
860  * produce zero, some throw an exception. We can dodge the problem by
861  * recognizing that division by -1 is the same as negation.
862  */
863  if (arg2 == -1)
864  {
865  if (unlikely(arg1 == PG_INT64_MIN))
866  ereport(ERROR,
867  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
868  errmsg("bigint out of range")));
869  result = -arg1;
870  PG_RETURN_INT64(result);
871  }
872 
873  /* No overflow is possible */
874 
875  result = arg1 / arg2;
876 
877  PG_RETURN_INT64(result);
878 }
879 
880 Datum
882 {
883  int32 arg1 = PG_GETARG_INT32(0);
884  int64 arg2 = PG_GETARG_INT64(1);
885  int64 result;
886 
887  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
888  ereport(ERROR,
889  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
890  errmsg("bigint out of range")));
891  PG_RETURN_INT64(result);
892 }
893 
894 Datum
896 {
897  int32 arg1 = PG_GETARG_INT32(0);
898  int64 arg2 = PG_GETARG_INT64(1);
899  int64 result;
900 
901  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
902  ereport(ERROR,
903  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
904  errmsg("bigint out of range")));
905  PG_RETURN_INT64(result);
906 }
907 
908 Datum
910 {
911  int32 arg1 = PG_GETARG_INT32(0);
912  int64 arg2 = PG_GETARG_INT64(1);
913  int64 result;
914 
915  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
916  ereport(ERROR,
917  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
918  errmsg("bigint out of range")));
919  PG_RETURN_INT64(result);
920 }
921 
922 Datum
924 {
925  int32 arg1 = PG_GETARG_INT32(0);
926  int64 arg2 = PG_GETARG_INT64(1);
927 
928  if (unlikely(arg2 == 0))
929  {
930  ereport(ERROR,
931  (errcode(ERRCODE_DIVISION_BY_ZERO),
932  errmsg("division by zero")));
933  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
934  PG_RETURN_NULL();
935  }
936 
937  /* No overflow is possible */
938  PG_RETURN_INT64((int64) arg1 / arg2);
939 }
940 
941 Datum
943 {
944  int64 arg1 = PG_GETARG_INT64(0);
945  int16 arg2 = PG_GETARG_INT16(1);
946  int64 result;
947 
948  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
949  ereport(ERROR,
950  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
951  errmsg("bigint out of range")));
952  PG_RETURN_INT64(result);
953 }
954 
955 Datum
957 {
958  int64 arg1 = PG_GETARG_INT64(0);
959  int16 arg2 = PG_GETARG_INT16(1);
960  int64 result;
961 
962  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
963  ereport(ERROR,
964  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
965  errmsg("bigint out of range")));
966  PG_RETURN_INT64(result);
967 }
968 
969 Datum
971 {
972  int64 arg1 = PG_GETARG_INT64(0);
973  int16 arg2 = PG_GETARG_INT16(1);
974  int64 result;
975 
976  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
977  ereport(ERROR,
978  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
979  errmsg("bigint out of range")));
980  PG_RETURN_INT64(result);
981 }
982 
983 Datum
985 {
986  int64 arg1 = PG_GETARG_INT64(0);
987  int16 arg2 = PG_GETARG_INT16(1);
988  int64 result;
989 
990  if (unlikely(arg2 == 0))
991  {
992  ereport(ERROR,
993  (errcode(ERRCODE_DIVISION_BY_ZERO),
994  errmsg("division by zero")));
995  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
996  PG_RETURN_NULL();
997  }
998 
999  /*
1000  * INT64_MIN / -1 is problematic, since the result can't be represented on
1001  * a two's-complement machine. Some machines produce INT64_MIN, some
1002  * produce zero, some throw an exception. We can dodge the problem by
1003  * recognizing that division by -1 is the same as negation.
1004  */
1005  if (arg2 == -1)
1006  {
1007  if (unlikely(arg1 == PG_INT64_MIN))
1008  ereport(ERROR,
1009  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1010  errmsg("bigint out of range")));
1011  result = -arg1;
1012  PG_RETURN_INT64(result);
1013  }
1014 
1015  /* No overflow is possible */
1016 
1017  result = arg1 / arg2;
1018 
1019  PG_RETURN_INT64(result);
1020 }
1021 
1022 Datum
1024 {
1025  int16 arg1 = PG_GETARG_INT16(0);
1026  int64 arg2 = PG_GETARG_INT64(1);
1027  int64 result;
1028 
1029  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
1030  ereport(ERROR,
1031  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1032  errmsg("bigint out of range")));
1033  PG_RETURN_INT64(result);
1034 }
1035 
1036 Datum
1038 {
1039  int16 arg1 = PG_GETARG_INT16(0);
1040  int64 arg2 = PG_GETARG_INT64(1);
1041  int64 result;
1042 
1043  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1044  ereport(ERROR,
1045  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1046  errmsg("bigint out of range")));
1047  PG_RETURN_INT64(result);
1048 }
1049 
1050 Datum
1052 {
1053  int16 arg1 = PG_GETARG_INT16(0);
1054  int64 arg2 = PG_GETARG_INT64(1);
1055  int64 result;
1056 
1057  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1058  ereport(ERROR,
1059  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1060  errmsg("bigint out of range")));
1061  PG_RETURN_INT64(result);
1062 }
1063 
1064 Datum
1066 {
1067  int16 arg1 = PG_GETARG_INT16(0);
1068  int64 arg2 = PG_GETARG_INT64(1);
1069 
1070  if (unlikely(arg2 == 0))
1071  {
1072  ereport(ERROR,
1073  (errcode(ERRCODE_DIVISION_BY_ZERO),
1074  errmsg("division by zero")));
1075  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1076  PG_RETURN_NULL();
1077  }
1078 
1079  /* No overflow is possible */
1080  PG_RETURN_INT64((int64) arg1 / arg2);
1081 }
1082 
1083 /* Binary arithmetics
1084  *
1085  * int8and - returns arg1 & arg2
1086  * int8or - returns arg1 | arg2
1087  * int8xor - returns arg1 # arg2
1088  * int8not - returns ~arg1
1089  * int8shl - returns arg1 << arg2
1090  * int8shr - returns arg1 >> arg2
1091  */
1092 
1093 Datum
1095 {
1096  int64 arg1 = PG_GETARG_INT64(0);
1097  int64 arg2 = PG_GETARG_INT64(1);
1098 
1099  PG_RETURN_INT64(arg1 & arg2);
1100 }
1101 
1102 Datum
1104 {
1105  int64 arg1 = PG_GETARG_INT64(0);
1106  int64 arg2 = PG_GETARG_INT64(1);
1107 
1108  PG_RETURN_INT64(arg1 | arg2);
1109 }
1110 
1111 Datum
1113 {
1114  int64 arg1 = PG_GETARG_INT64(0);
1115  int64 arg2 = PG_GETARG_INT64(1);
1116 
1117  PG_RETURN_INT64(arg1 ^ arg2);
1118 }
1119 
1120 Datum
1122 {
1123  int64 arg1 = PG_GETARG_INT64(0);
1124 
1125  PG_RETURN_INT64(~arg1);
1126 }
1127 
1128 Datum
1130 {
1131  int64 arg1 = PG_GETARG_INT64(0);
1132  int32 arg2 = PG_GETARG_INT32(1);
1133 
1134  PG_RETURN_INT64(arg1 << arg2);
1135 }
1136 
1137 Datum
1139 {
1140  int64 arg1 = PG_GETARG_INT64(0);
1141  int32 arg2 = PG_GETARG_INT32(1);
1142 
1143  PG_RETURN_INT64(arg1 >> arg2);
1144 }
1145 
1146 /*----------------------------------------------------------
1147  * Conversion operators.
1148  *---------------------------------------------------------*/
1149 
1150 Datum
1152 {
1153  int32 arg = PG_GETARG_INT32(0);
1154 
1155  PG_RETURN_INT64((int64) arg);
1156 }
1157 
1158 Datum
1160 {
1161  int64 arg = PG_GETARG_INT64(0);
1162 
1163  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1164  ereport(ERROR,
1165  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1166  errmsg("integer out of range")));
1167 
1168  PG_RETURN_INT32((int32) arg);
1169 }
1170 
1171 Datum
1173 {
1174  int16 arg = PG_GETARG_INT16(0);
1175 
1176  PG_RETURN_INT64((int64) arg);
1177 }
1178 
1179 Datum
1181 {
1182  int64 arg = PG_GETARG_INT64(0);
1183 
1184  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1185  ereport(ERROR,
1186  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1187  errmsg("smallint out of range")));
1188 
1189  PG_RETURN_INT16((int16) arg);
1190 }
1191 
1192 Datum
1194 {
1195  int64 arg = PG_GETARG_INT64(0);
1196  float8 result;
1197 
1198  result = arg;
1199 
1200  PG_RETURN_FLOAT8(result);
1201 }
1202 
1203 /* dtoi8()
1204  * Convert float8 to 8-byte integer.
1205  */
1206 Datum
1208 {
1209  float8 num = PG_GETARG_FLOAT8(0);
1210 
1211  /*
1212  * Get rid of any fractional part in the input. This is so we don't fail
1213  * on just-out-of-range values that would round into range. Note
1214  * assumption that rint() will pass through a NaN or Inf unchanged.
1215  */
1216  num = rint(num);
1217 
1218  /* Range check */
1219  if (unlikely(isnan(num) || !FLOAT8_FITS_IN_INT64(num)))
1220  ereport(ERROR,
1221  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1222  errmsg("bigint out of range")));
1223 
1224  PG_RETURN_INT64((int64) num);
1225 }
1226 
1227 Datum
1229 {
1230  int64 arg = PG_GETARG_INT64(0);
1231  float4 result;
1232 
1233  result = arg;
1234 
1235  PG_RETURN_FLOAT4(result);
1236 }
1237 
1238 /* ftoi8()
1239  * Convert float4 to 8-byte integer.
1240  */
1241 Datum
1243 {
1244  float4 num = PG_GETARG_FLOAT4(0);
1245 
1246  /*
1247  * Get rid of any fractional part in the input. This is so we don't fail
1248  * on just-out-of-range values that would round into range. Note
1249  * assumption that rint() will pass through a NaN or Inf unchanged.
1250  */
1251  num = rint(num);
1252 
1253  /* Range check */
1254  if (unlikely(isnan(num) || !FLOAT4_FITS_IN_INT64(num)))
1255  ereport(ERROR,
1256  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1257  errmsg("bigint out of range")));
1258 
1259  PG_RETURN_INT64((int64) num);
1260 }
1261 
1262 Datum
1264 {
1265  int64 arg = PG_GETARG_INT64(0);
1266 
1267  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1268  ereport(ERROR,
1269  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1270  errmsg("OID out of range")));
1271 
1272  PG_RETURN_OID((Oid) arg);
1273 }
1274 
1275 Datum
1277 {
1278  Oid arg = PG_GETARG_OID(0);
1279 
1280  PG_RETURN_INT64((int64) arg);
1281 }
1282 
1283 /*
1284  * non-persistent numeric series generator
1285  */
1286 Datum
1288 {
1289  return generate_series_step_int8(fcinfo);
1290 }
1291 
1292 Datum
1294 {
1295  FuncCallContext *funcctx;
1296  generate_series_fctx *fctx;
1297  int64 result;
1298  MemoryContext oldcontext;
1299 
1300  /* stuff done only on the first call of the function */
1301  if (SRF_IS_FIRSTCALL())
1302  {
1303  int64 start = PG_GETARG_INT64(0);
1304  int64 finish = PG_GETARG_INT64(1);
1305  int64 step = 1;
1306 
1307  /* see if we were given an explicit step size */
1308  if (PG_NARGS() == 3)
1309  step = PG_GETARG_INT64(2);
1310  if (step == 0)
1311  ereport(ERROR,
1312  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1313  errmsg("step size cannot equal zero")));
1314 
1315  /* create a function context for cross-call persistence */
1316  funcctx = SRF_FIRSTCALL_INIT();
1317 
1318  /*
1319  * switch to memory context appropriate for multiple function calls
1320  */
1321  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1322 
1323  /* allocate memory for user context */
1324  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1325 
1326  /*
1327  * Use fctx to keep state from call to call. Seed current with the
1328  * original start value
1329  */
1330  fctx->current = start;
1331  fctx->finish = finish;
1332  fctx->step = step;
1333 
1334  funcctx->user_fctx = fctx;
1335  MemoryContextSwitchTo(oldcontext);
1336  }
1337 
1338  /* stuff done on every call of the function */
1339  funcctx = SRF_PERCALL_SETUP();
1340 
1341  /*
1342  * get the saved state and use current as the result for this iteration
1343  */
1344  fctx = funcctx->user_fctx;
1345  result = fctx->current;
1346 
1347  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1348  (fctx->step < 0 && fctx->current >= fctx->finish))
1349  {
1350  /*
1351  * Increment current in preparation for next iteration. If next-value
1352  * computation overflows, this is the final result.
1353  */
1354  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1355  fctx->step = 0;
1356 
1357  /* do when there is more left to send */
1358  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1359  }
1360  else
1361  /* do when there is no more left */
1362  SRF_RETURN_DONE(funcctx);
1363 }
1364 
1365 /*
1366  * Planner support function for generate_series(int8, int8 [, int8])
1367  */
1368 Datum
1370 {
1371  Node *rawreq = (Node *) PG_GETARG_POINTER(0);
1372  Node *ret = NULL;
1373 
1374  if (IsA(rawreq, SupportRequestRows))
1375  {
1376  /* Try to estimate the number of rows returned */
1377  SupportRequestRows *req = (SupportRequestRows *) rawreq;
1378 
1379  if (is_funcclause(req->node)) /* be paranoid */
1380  {
1381  List *args = ((FuncExpr *) req->node)->args;
1382  Node *arg1,
1383  *arg2,
1384  *arg3;
1385 
1386  /* We can use estimated argument values here */
1387  arg1 = estimate_expression_value(req->root, linitial(args));
1388  arg2 = estimate_expression_value(req->root, lsecond(args));
1389  if (list_length(args) >= 3)
1390  arg3 = estimate_expression_value(req->root, lthird(args));
1391  else
1392  arg3 = NULL;
1393 
1394  /*
1395  * If any argument is constant NULL, we can safely assume that
1396  * zero rows are returned. Otherwise, if they're all non-NULL
1397  * constants, we can calculate the number of rows that will be
1398  * returned. Use double arithmetic to avoid overflow hazards.
1399  */
1400  if ((IsA(arg1, Const) &&
1401  ((Const *) arg1)->constisnull) ||
1402  (IsA(arg2, Const) &&
1403  ((Const *) arg2)->constisnull) ||
1404  (arg3 != NULL && IsA(arg3, Const) &&
1405  ((Const *) arg3)->constisnull))
1406  {
1407  req->rows = 0;
1408  ret = (Node *) req;
1409  }
1410  else if (IsA(arg1, Const) &&
1411  IsA(arg2, Const) &&
1412  (arg3 == NULL || IsA(arg3, Const)))
1413  {
1414  double start,
1415  finish,
1416  step;
1417 
1418  start = DatumGetInt64(((Const *) arg1)->constvalue);
1419  finish = DatumGetInt64(((Const *) arg2)->constvalue);
1420  step = arg3 ? DatumGetInt64(((Const *) arg3)->constvalue) : 1;
1421 
1422  /* This equation works for either sign of step */
1423  if (step != 0)
1424  {
1425  req->rows = floor((finish - start + step) / step);
1426  ret = (Node *) req;
1427  }
1428  }
1429  }
1430  }
1431 
1432  PG_RETURN_POINTER(ret);
1433 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:276
signed short int16
Definition: c.h:346
Datum int8lt(PG_FUNCTION_ARGS)
Definition: int8.c:211
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:351
Datum int8ge(PG_FUNCTION_ARGS)
Definition: int8.c:238
#define PG_GETARG_INT32(n)
Definition: fmgr.h:264
#define IsA(nodeptr, _type_)
Definition: nodes.h:576
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:355
Datum int84ge(PG_FUNCTION_ARGS)
Definition: int8.c:295
Datum int82mul(PG_FUNCTION_ARGS)
Definition: int8.c:970
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1293
#define MAXINT8LEN
Definition: int8.c:29
Datum int82eq(PG_FUNCTION_ARGS)
Definition: int8.c:364
Datum int8xor(PG_FUNCTION_ARGS)
Definition: int8.c:1112
Node * estimate_expression_value(PlannerInfo *root, Node *node)
Definition: clauses.c:2286
Datum int82ge(PG_FUNCTION_ARGS)
Definition: int8.c:409
Datum int48div(PG_FUNCTION_ARGS)
Definition: int8.c:923
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:188
#define PG_RETURN_INT64(x)
Definition: fmgr.h:357
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:283
void pq_begintypsend(StringInfo buf)
Definition: pqformat.c:328
Datum int28gt(PG_FUNCTION_ARGS)
Definition: int8.c:448
char * pstrdup(const char *in)
Definition: mcxt.c:1186
Datum int8pl(PG_FUNCTION_ARGS)
Definition: int8.c:542
StringInfoData * StringInfo
Definition: stringinfo.h:44
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:356
Datum generate_series_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1287
Datum int28eq(PG_FUNCTION_ARGS)
Definition: int8.c:421
static MemoryContext MemoryContextSwitchTo(MemoryContext context)
Definition: palloc.h:109
#define PG_RETURN_INT32(x)
Definition: fmgr.h:344
Datum int84div(PG_FUNCTION_ARGS)
Definition: int8.c:842
Definition: nodes.h:525
#define PG_RETURN_INT16(x)
Definition: fmgr.h:346
int errcode(int sqlerrcode)
Definition: elog.c:608
Datum int28div(PG_FUNCTION_ARGS)
Definition: int8.c:1065
Datum int8le(PG_FUNCTION_ARGS)
Definition: int8.c:229
Datum int8mi(PG_FUNCTION_ARGS)
Definition: int8.c:556
Datum generate_series_int8_support(PG_FUNCTION_ARGS)
Definition: int8.c:1369
Datum int82pl(PG_FUNCTION_ARGS)
Definition: int8.c:942
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:271
Datum int82mi(PG_FUNCTION_ARGS)
Definition: int8.c:956
#define PG_GETARG_BOOL(n)
Definition: fmgr.h:269
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:360
#define PG_UINT32_MAX
Definition: c.h:443
static void pq_sendint64(StringInfo buf, uint64 i)
Definition: pqformat.h:153
unsigned int Oid
Definition: postgres_ext.h:31
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:287
Datum int48mi(PG_FUNCTION_ARGS)
Definition: int8.c:895
Datum i8tooid(PG_FUNCTION_ARGS)
Definition: int8.c:1263
#define lsecond(l)
Definition: pg_list.h:200
Datum int48ge(PG_FUNCTION_ARGS)
Definition: int8.c:352
signed int int32
Definition: c.h:347
static bool is_funcclause(const void *clause)
Definition: nodeFuncs.h:56
Datum int8larger(PG_FUNCTION_ARGS)
Definition: int8.c:776
Datum int8smaller(PG_FUNCTION_ARGS)
Definition: int8.c:788
struct PlannerInfo * root
Definition: supportnodes.h:163
Datum ftoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1242
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:289
Datum in_range_int8_int8(PG_FUNCTION_ARGS)
Definition: int8.c:481
Datum int8inc_float8_float8(PG_FUNCTION_ARGS)
Definition: int8.c:763
Datum int48eq(PG_FUNCTION_ARGS)
Definition: int8.c:307
#define linitial(l)
Definition: pg_list.h:195
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:492
Datum int82le(PG_FUNCTION_ARGS)
Definition: int8.c:400
Datum int8and(PG_FUNCTION_ARGS)
Definition: int8.c:1094
Datum int28ge(PG_FUNCTION_ARGS)
Definition: int8.c:466
#define FLOAT8_FITS_IN_INT64(num)
Definition: c.h:1055
Datum int8eq(PG_FUNCTION_ARGS)
Definition: int8.c:193
#define DatumGetInt64(X)
Definition: postgres.h:607
Datum int8gt(PG_FUNCTION_ARGS)
Definition: int8.c:220
static char * buf
Definition: pg_test_fsync.c:67
Datum int82gt(PG_FUNCTION_ARGS)
Definition: int8.c:391
Datum int8mul(PG_FUNCTION_ARGS)
Definition: int8.c:570
#define PG_INT64_MIN
Definition: c.h:444
#define PG_GETARG_OID(n)
Definition: fmgr.h:270
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:672
Datum dtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1207
Datum int8div(PG_FUNCTION_ARGS)
Definition: int8.c:584
Datum int48gt(PG_FUNCTION_ARGS)
Definition: int8.c:334
Datum int84lt(PG_FUNCTION_ARGS)
Definition: int8.c:268
Datum Int64GetDatum(int64 X)
Definition: fmgr.c:1699
double rint(double x)
Definition: rint.c:21
#define PG_INT16_MIN
Definition: c.h:438
#define PG_INT32_MIN
Definition: c.h:441
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:275
#define ereport(elevel, rest)
Definition: elog.h:141
Datum int48lt(PG_FUNCTION_ARGS)
Definition: int8.c:325
Datum int8um(PG_FUNCTION_ARGS)
Definition: int8.c:520
Datum int84le(PG_FUNCTION_ARGS)
Definition: int8.c:286
Datum int84mul(PG_FUNCTION_ARGS)
Definition: int8.c:828
signed char int8
Definition: c.h:345
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:710
float float4
Definition: c.h:491
Datum int48pl(PG_FUNCTION_ARGS)
Definition: int8.c:881
Datum int8dec_any(PG_FUNCTION_ARGS)
Definition: int8.c:769
Datum int8ne(PG_FUNCTION_ARGS)
Definition: int8.c:202
Datum int84ne(PG_FUNCTION_ARGS)
Definition: int8.c:259
#define PG_RETURN_BOOL(x)
Definition: fmgr.h:349
uintptr_t Datum
Definition: postgres.h:367
Datum int82div(PG_FUNCTION_ARGS)
Definition: int8.c:984
Datum int82(PG_FUNCTION_ARGS)
Definition: int8.c:1180
Datum int82lt(PG_FUNCTION_ARGS)
Definition: int8.c:382
#define PG_GETARG_INT16(n)
Definition: fmgr.h:266
Datum int84gt(PG_FUNCTION_ARGS)
Definition: int8.c:277
Datum int28ne(PG_FUNCTION_ARGS)
Definition: int8.c:430
#define FLOAT4_FITS_IN_INT64(num)
Definition: c.h:1049
Datum int8shr(PG_FUNCTION_ARGS)
Definition: int8.c:1138
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:161
Datum int28le(PG_FUNCTION_ARGS)
Definition: int8.c:457
int32 current
Definition: int.c:49
int32 finish
Definition: int.c:50
Datum int84pl(PG_FUNCTION_ARGS)
Definition: int8.c:800
Datum int8shl(PG_FUNCTION_ARGS)
Definition: int8.c:1129
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:215
Datum int48mul(PG_FUNCTION_ARGS)
Definition: int8.c:909
Datum i8tod(PG_FUNCTION_ARGS)
Definition: int8.c:1193
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:352
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:102
Datum int82ne(PG_FUNCTION_ARGS)
Definition: int8.c:373
Datum int8recv(PG_FUNCTION_ARGS)
Definition: int8.c:163
Datum int28mul(PG_FUNCTION_ARGS)
Definition: int8.c:1051
static int list_length(const List *l)
Definition: pg_list.h:169
Datum int8send(PG_FUNCTION_ARGS)
Definition: int8.c:174
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:3571
#define PG_INT16_MAX
Definition: c.h:439
Datum int84eq(PG_FUNCTION_ARGS)
Definition: int8.c:250
#define PG_NARGS()
Definition: fmgr.h:198
Datum int8in(PG_FUNCTION_ARGS)
Definition: int8.c:135
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:339
Datum int28lt(PG_FUNCTION_ARGS)
Definition: int8.c:439
Datum int8abs(PG_FUNCTION_ARGS)
Definition: int8.c:626
Datum int28(PG_FUNCTION_ARGS)
Definition: int8.c:1172
Datum int84(PG_FUNCTION_ARGS)
Definition: int8.c:1159
Datum i8tof(PG_FUNCTION_ARGS)
Definition: int8.c:1228
void * user_fctx
Definition: funcapi.h:83
Datum int84mi(PG_FUNCTION_ARGS)
Definition: int8.c:814
void * palloc(Size size)
Definition: mcxt.c:949
int errmsg(const char *fmt,...)
Definition: elog.c:822
Datum int8or(PG_FUNCTION_ARGS)
Definition: int8.c:1103
#define PG_INT32_MAX
Definition: c.h:442
Datum int48(PG_FUNCTION_ARGS)
Definition: int8.c:1151
Datum int28pl(PG_FUNCTION_ARGS)
Definition: int8.c:1023
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
void * arg
#define unlikely(x)
Definition: c.h:208
#define lthird(l)
Definition: pg_list.h:205
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:272
#define PG_FUNCTION_ARGS
Definition: fmgr.h:188
Datum int8inc_any(PG_FUNCTION_ARGS)
Definition: int8.c:757
Datum int48ne(PG_FUNCTION_ARGS)
Definition: int8.c:316
Datum int8not(PG_FUNCTION_ARGS)
Definition: int8.c:1121
Datum int28mi(PG_FUNCTION_ARGS)
Definition: int8.c:1037
#define PG_GETARG_INT64(n)
Definition: fmgr.h:277
Datum int48le(PG_FUNCTION_ARGS)
Definition: int8.c:343
Definition: pg_list.h:50
#define PG_RETURN_OID(x)
Definition: fmgr.h:350
Datum oidtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1276
long val
Definition: informix.c:684
Datum int8out(PG_FUNCTION_ARGS)
Definition: int8.c:148
#define PG_RETURN_NULL()
Definition: fmgr.h:335
Datum int8up(PG_FUNCTION_ARGS)
Definition: int8.c:534
Datum int8mod(PG_FUNCTION_ARGS)
Definition: int8.c:643
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:307
bool scanint8(const char *str, bool errorOK, int64 *result)
Definition: int8.c:56
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:285