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-2017, 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 "utils/int8.h"
24 #include "utils/builtins.h"
25 
26 
27 #define MAXINT8LEN 25
28 
29 typedef struct
30 {
31  int64 current;
32  int64 finish;
33  int64 step;
35 
36 
37 /***********************************************************************
38  **
39  ** Routines for 64-bit integers.
40  **
41  ***********************************************************************/
42 
43 /*----------------------------------------------------------
44  * Formatting and conversion routines.
45  *---------------------------------------------------------*/
46 
47 /*
48  * scanint8 --- try to parse a string into an int8.
49  *
50  * If errorOK is false, ereport a useful error message if the string is bad.
51  * If errorOK is true, just return "false" for bad input.
52  */
53 bool
54 scanint8(const char *str, bool errorOK, int64 *result)
55 {
56  const char *ptr = str;
57  int64 tmp = 0;
58  bool neg = false;
59 
60  /*
61  * Do our own scan, rather than relying on sscanf which might be broken
62  * for long long.
63  *
64  * As INT64_MIN can't be stored as a positive 64 bit integer, accumulate
65  * value as a negative number.
66  */
67 
68  /* skip leading spaces */
69  while (*ptr && isspace((unsigned char) *ptr))
70  ptr++;
71 
72  /* handle sign */
73  if (*ptr == '-')
74  {
75  ptr++;
76  neg = true;
77  }
78  else if (*ptr == '+')
79  ptr++;
80 
81  /* require at least one digit */
82  if (unlikely(!isdigit((unsigned char) *ptr)))
83  {
84  goto invalid_syntax;
85  }
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  if (unlikely(tmp == PG_INT64_MIN))
107  goto out_of_range;
108  tmp = -tmp;
109  }
110  *result = tmp;
111 
112  return true;
113 
114 out_of_range:
115  if (errorOK)
116  return false;
117  else
118  ereport(ERROR,
119  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
120  errmsg("value \"%s\" is out of range for type %s",
121  str, "bigint")));
122 invalid_syntax:
123  if (errorOK)
124  return false;
125  else
126  ereport(ERROR,
127  (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
128  errmsg("invalid input syntax for integer: \"%s\"",
129  str)));
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 /*----------------------------------------------------------
476  * Arithmetic operators on 64-bit integers.
477  *---------------------------------------------------------*/
478 
479 Datum
481 {
482  int64 arg = PG_GETARG_INT64(0);
483  int64 result;
484 
485  if (unlikely(arg == PG_INT64_MIN))
486  ereport(ERROR,
487  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
488  errmsg("bigint out of range")));
489  result = -arg;
490  PG_RETURN_INT64(result);
491 }
492 
493 Datum
495 {
496  int64 arg = PG_GETARG_INT64(0);
497 
498  PG_RETURN_INT64(arg);
499 }
500 
501 Datum
503 {
504  int64 arg1 = PG_GETARG_INT64(0);
505  int64 arg2 = PG_GETARG_INT64(1);
506  int64 result;
507 
508  if (unlikely(pg_add_s64_overflow(arg1, arg2, &result)))
509  ereport(ERROR,
510  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
511  errmsg("bigint out of range")));
512  PG_RETURN_INT64(result);
513 }
514 
515 Datum
517 {
518  int64 arg1 = PG_GETARG_INT64(0);
519  int64 arg2 = PG_GETARG_INT64(1);
520  int64 result;
521 
522  if (unlikely(pg_sub_s64_overflow(arg1, arg2, &result)))
523  ereport(ERROR,
524  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
525  errmsg("bigint out of range")));
526  PG_RETURN_INT64(result);
527 }
528 
529 Datum
531 {
532  int64 arg1 = PG_GETARG_INT64(0);
533  int64 arg2 = PG_GETARG_INT64(1);
534  int64 result;
535 
536  if (unlikely(pg_mul_s64_overflow(arg1, arg2, &result)))
537  ereport(ERROR,
538  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
539  errmsg("bigint out of range")));
540  PG_RETURN_INT64(result);
541 }
542 
543 Datum
545 {
546  int64 arg1 = PG_GETARG_INT64(0);
547  int64 arg2 = PG_GETARG_INT64(1);
548  int64 result;
549 
550  if (arg2 == 0)
551  {
552  ereport(ERROR,
553  (errcode(ERRCODE_DIVISION_BY_ZERO),
554  errmsg("division by zero")));
555  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
556  PG_RETURN_NULL();
557  }
558 
559  /*
560  * INT64_MIN / -1 is problematic, since the result can't be represented on
561  * a two's-complement machine. Some machines produce INT64_MIN, some
562  * produce zero, some throw an exception. We can dodge the problem by
563  * recognizing that division by -1 is the same as negation.
564  */
565  if (arg2 == -1)
566  {
567  if (unlikely(arg1 == PG_INT64_MIN))
568  ereport(ERROR,
569  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
570  errmsg("bigint out of range")));
571  result = -arg1;
572  PG_RETURN_INT64(result);
573  }
574 
575  /* No overflow is possible */
576 
577  result = arg1 / arg2;
578 
579  PG_RETURN_INT64(result);
580 }
581 
582 /* int8abs()
583  * Absolute value
584  */
585 Datum
587 {
588  int64 arg1 = PG_GETARG_INT64(0);
589  int64 result;
590 
591  if (unlikely(arg1 == PG_INT64_MIN))
592  ereport(ERROR,
593  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
594  errmsg("bigint out of range")));
595  result = (arg1 < 0) ? -arg1 : arg1;
596  PG_RETURN_INT64(result);
597 }
598 
599 /* int8mod()
600  * Modulo operation.
601  */
602 Datum
604 {
605  int64 arg1 = PG_GETARG_INT64(0);
606  int64 arg2 = PG_GETARG_INT64(1);
607 
608  if (unlikely(arg2 == 0))
609  {
610  ereport(ERROR,
611  (errcode(ERRCODE_DIVISION_BY_ZERO),
612  errmsg("division by zero")));
613  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
614  PG_RETURN_NULL();
615  }
616 
617  /*
618  * Some machines throw a floating-point exception for INT64_MIN % -1,
619  * which is a bit silly since the correct answer is perfectly
620  * well-defined, namely zero.
621  */
622  if (arg2 == -1)
623  PG_RETURN_INT64(0);
624 
625  /* No overflow is possible */
626 
627  PG_RETURN_INT64(arg1 % arg2);
628 }
629 
630 
631 Datum
633 {
634  /*
635  * When int8 is pass-by-reference, we provide this special case to avoid
636  * palloc overhead for COUNT(): when called as an aggregate, we know that
637  * the argument is modifiable local storage, so just update it in-place.
638  * (If int8 is pass-by-value, then of course this is useless as well as
639  * incorrect, so just ifdef it out.)
640  */
641 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
642  if (AggCheckCallContext(fcinfo, NULL))
643  {
644  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
645 
646  if (unlikely(pg_add_s64_overflow(*arg, 1, arg)))
647  ereport(ERROR,
648  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
649  errmsg("bigint out of range")));
650 
651  PG_RETURN_POINTER(arg);
652  }
653  else
654 #endif
655  {
656  /* Not called as an aggregate, so just do it the dumb way */
657  int64 arg = PG_GETARG_INT64(0);
658  int64 result;
659 
660  if (unlikely(pg_add_s64_overflow(arg, 1, &result)))
661  ereport(ERROR,
662  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
663  errmsg("bigint out of range")));
664 
665  PG_RETURN_INT64(result);
666  }
667 }
668 
669 Datum
671 {
672  /*
673  * When int8 is pass-by-reference, we provide this special case to avoid
674  * palloc overhead for COUNT(): when called as an aggregate, we know that
675  * the argument is modifiable local storage, so just update it in-place.
676  * (If int8 is pass-by-value, then of course this is useless as well as
677  * incorrect, so just ifdef it out.)
678  */
679 #ifndef USE_FLOAT8_BYVAL /* controls int8 too */
680  if (AggCheckCallContext(fcinfo, NULL))
681  {
682  int64 *arg = (int64 *) PG_GETARG_POINTER(0);
683 
684  if (unlikely(pg_sub_s64_overflow(*arg, 1, arg)))
685  ereport(ERROR,
686  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
687  errmsg("bigint out of range")));
688  PG_RETURN_POINTER(arg);
689  }
690  else
691 #endif
692  {
693  /* Not called as an aggregate, so just do it the dumb way */
694  int64 arg = PG_GETARG_INT64(0);
695  int64 result;
696 
697  if (unlikely(pg_sub_s64_overflow(arg, 1, &result)))
698  ereport(ERROR,
699  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
700  errmsg("bigint out of range")));
701 
702  PG_RETURN_INT64(result);
703  }
704 }
705 
706 
707 /*
708  * These functions are exactly like int8inc/int8dec but are used for
709  * aggregates that count only non-null values. Since the functions are
710  * declared strict, the null checks happen before we ever get here, and all we
711  * need do is increment the state value. We could actually make these pg_proc
712  * entries point right at int8inc/int8dec, but then the opr_sanity regression
713  * test would complain about mismatched entries for a built-in function.
714  */
715 
716 Datum
718 {
719  return int8inc(fcinfo);
720 }
721 
722 Datum
724 {
725  return int8inc(fcinfo);
726 }
727 
728 Datum
730 {
731  return int8dec(fcinfo);
732 }
733 
734 
735 Datum
737 {
738  int64 arg1 = PG_GETARG_INT64(0);
739  int64 arg2 = PG_GETARG_INT64(1);
740  int64 result;
741 
742  result = ((arg1 > arg2) ? arg1 : arg2);
743 
744  PG_RETURN_INT64(result);
745 }
746 
747 Datum
749 {
750  int64 arg1 = PG_GETARG_INT64(0);
751  int64 arg2 = PG_GETARG_INT64(1);
752  int64 result;
753 
754  result = ((arg1 < arg2) ? arg1 : arg2);
755 
756  PG_RETURN_INT64(result);
757 }
758 
759 Datum
761 {
762  int64 arg1 = PG_GETARG_INT64(0);
763  int32 arg2 = PG_GETARG_INT32(1);
764  int64 result;
765 
766  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
767  ereport(ERROR,
768  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
769  errmsg("bigint out of range")));
770  PG_RETURN_INT64(result);
771 }
772 
773 Datum
775 {
776  int64 arg1 = PG_GETARG_INT64(0);
777  int32 arg2 = PG_GETARG_INT32(1);
778  int64 result;
779 
780  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
781  ereport(ERROR,
782  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
783  errmsg("bigint out of range")));
784  PG_RETURN_INT64(result);
785 }
786 
787 Datum
789 {
790  int64 arg1 = PG_GETARG_INT64(0);
791  int32 arg2 = PG_GETARG_INT32(1);
792  int64 result;
793 
794  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
795  ereport(ERROR,
796  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
797  errmsg("bigint out of range")));
798  PG_RETURN_INT64(result);
799 }
800 
801 Datum
803 {
804  int64 arg1 = PG_GETARG_INT64(0);
805  int32 arg2 = PG_GETARG_INT32(1);
806  int64 result;
807 
808  if (arg2 == 0)
809  {
810  ereport(ERROR,
811  (errcode(ERRCODE_DIVISION_BY_ZERO),
812  errmsg("division by zero")));
813  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
814  PG_RETURN_NULL();
815  }
816 
817  /*
818  * INT64_MIN / -1 is problematic, since the result can't be represented on
819  * a two's-complement machine. Some machines produce INT64_MIN, some
820  * produce zero, some throw an exception. We can dodge the problem by
821  * recognizing that division by -1 is the same as negation.
822  */
823  if (arg2 == -1)
824  {
825  if (unlikely(arg1 == PG_INT64_MIN))
826  ereport(ERROR,
827  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
828  errmsg("bigint out of range")));
829  result = -arg1;
830  PG_RETURN_INT64(result);
831  }
832 
833  /* No overflow is possible */
834 
835  result = arg1 / arg2;
836 
837  PG_RETURN_INT64(result);
838 }
839 
840 Datum
842 {
843  int32 arg1 = PG_GETARG_INT32(0);
844  int64 arg2 = PG_GETARG_INT64(1);
845  int64 result;
846 
847  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
848  ereport(ERROR,
849  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
850  errmsg("bigint out of range")));
851  PG_RETURN_INT64(result);
852 }
853 
854 Datum
856 {
857  int32 arg1 = PG_GETARG_INT32(0);
858  int64 arg2 = PG_GETARG_INT64(1);
859  int64 result;
860 
861  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
862  ereport(ERROR,
863  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
864  errmsg("bigint out of range")));
865  PG_RETURN_INT64(result);
866 }
867 
868 Datum
870 {
871  int32 arg1 = PG_GETARG_INT32(0);
872  int64 arg2 = PG_GETARG_INT64(1);
873  int64 result;
874 
875  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
876  ereport(ERROR,
877  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
878  errmsg("bigint out of range")));
879  PG_RETURN_INT64(result);
880 }
881 
882 Datum
884 {
885  int32 arg1 = PG_GETARG_INT32(0);
886  int64 arg2 = PG_GETARG_INT64(1);
887 
888  if (unlikely(arg2 == 0))
889  {
890  ereport(ERROR,
891  (errcode(ERRCODE_DIVISION_BY_ZERO),
892  errmsg("division by zero")));
893  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
894  PG_RETURN_NULL();
895  }
896 
897  /* No overflow is possible */
898  PG_RETURN_INT64((int64) arg1 / arg2);
899 }
900 
901 Datum
903 {
904  int64 arg1 = PG_GETARG_INT64(0);
905  int16 arg2 = PG_GETARG_INT16(1);
906  int64 result;
907 
908  if (unlikely(pg_add_s64_overflow(arg1, (int64) arg2, &result)))
909  ereport(ERROR,
910  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
911  errmsg("bigint out of range")));
912  PG_RETURN_INT64(result);
913 }
914 
915 Datum
917 {
918  int64 arg1 = PG_GETARG_INT64(0);
919  int16 arg2 = PG_GETARG_INT16(1);
920  int64 result;
921 
922  if (unlikely(pg_sub_s64_overflow(arg1, (int64) arg2, &result)))
923  ereport(ERROR,
924  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
925  errmsg("bigint out of range")));
926  PG_RETURN_INT64(result);
927 }
928 
929 Datum
931 {
932  int64 arg1 = PG_GETARG_INT64(0);
933  int16 arg2 = PG_GETARG_INT16(1);
934  int64 result;
935 
936  if (unlikely(pg_mul_s64_overflow(arg1, (int64) arg2, &result)))
937  ereport(ERROR,
938  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
939  errmsg("bigint out of range")));
940  PG_RETURN_INT64(result);
941 }
942 
943 Datum
945 {
946  int64 arg1 = PG_GETARG_INT64(0);
947  int16 arg2 = PG_GETARG_INT16(1);
948  int64 result;
949 
950  if (unlikely(arg2 == 0))
951  {
952  ereport(ERROR,
953  (errcode(ERRCODE_DIVISION_BY_ZERO),
954  errmsg("division by zero")));
955  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
956  PG_RETURN_NULL();
957  }
958 
959  /*
960  * INT64_MIN / -1 is problematic, since the result can't be represented on
961  * a two's-complement machine. Some machines produce INT64_MIN, some
962  * produce zero, some throw an exception. We can dodge the problem by
963  * recognizing that division by -1 is the same as negation.
964  */
965  if (arg2 == -1)
966  {
967  if (unlikely(arg1 == PG_INT64_MIN))
968  ereport(ERROR,
969  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
970  errmsg("bigint out of range")));
971  result = -arg1;
972  PG_RETURN_INT64(result);
973  }
974 
975  /* No overflow is possible */
976 
977  result = arg1 / arg2;
978 
979  PG_RETURN_INT64(result);
980 }
981 
982 Datum
984 {
985  int16 arg1 = PG_GETARG_INT16(0);
986  int64 arg2 = PG_GETARG_INT64(1);
987  int64 result;
988 
989  if (unlikely(pg_add_s64_overflow((int64) arg1, arg2, &result)))
990  ereport(ERROR,
991  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
992  errmsg("bigint out of range")));
993  PG_RETURN_INT64(result);
994 }
995 
996 Datum
998 {
999  int16 arg1 = PG_GETARG_INT16(0);
1000  int64 arg2 = PG_GETARG_INT64(1);
1001  int64 result;
1002 
1003  if (unlikely(pg_sub_s64_overflow((int64) arg1, arg2, &result)))
1004  ereport(ERROR,
1005  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1006  errmsg("bigint out of range")));
1007  PG_RETURN_INT64(result);
1008 }
1009 
1010 Datum
1012 {
1013  int16 arg1 = PG_GETARG_INT16(0);
1014  int64 arg2 = PG_GETARG_INT64(1);
1015  int64 result;
1016 
1017  if (unlikely(pg_mul_s64_overflow((int64) arg1, arg2, &result)))
1018  ereport(ERROR,
1019  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1020  errmsg("bigint out of range")));
1021  PG_RETURN_INT64(result);
1022 }
1023 
1024 Datum
1026 {
1027  int16 arg1 = PG_GETARG_INT16(0);
1028  int64 arg2 = PG_GETARG_INT64(1);
1029 
1030  if (unlikely(arg2 == 0))
1031  {
1032  ereport(ERROR,
1033  (errcode(ERRCODE_DIVISION_BY_ZERO),
1034  errmsg("division by zero")));
1035  /* ensure compiler realizes we mustn't reach the division (gcc bug) */
1036  PG_RETURN_NULL();
1037  }
1038 
1039  /* No overflow is possible */
1040  PG_RETURN_INT64((int64) arg1 / arg2);
1041 }
1042 
1043 /* Binary arithmetics
1044  *
1045  * int8and - returns arg1 & arg2
1046  * int8or - returns arg1 | arg2
1047  * int8xor - returns arg1 # arg2
1048  * int8not - returns ~arg1
1049  * int8shl - returns arg1 << arg2
1050  * int8shr - returns arg1 >> arg2
1051  */
1052 
1053 Datum
1055 {
1056  int64 arg1 = PG_GETARG_INT64(0);
1057  int64 arg2 = PG_GETARG_INT64(1);
1058 
1059  PG_RETURN_INT64(arg1 & arg2);
1060 }
1061 
1062 Datum
1064 {
1065  int64 arg1 = PG_GETARG_INT64(0);
1066  int64 arg2 = PG_GETARG_INT64(1);
1067 
1068  PG_RETURN_INT64(arg1 | arg2);
1069 }
1070 
1071 Datum
1073 {
1074  int64 arg1 = PG_GETARG_INT64(0);
1075  int64 arg2 = PG_GETARG_INT64(1);
1076 
1077  PG_RETURN_INT64(arg1 ^ arg2);
1078 }
1079 
1080 Datum
1082 {
1083  int64 arg1 = PG_GETARG_INT64(0);
1084 
1085  PG_RETURN_INT64(~arg1);
1086 }
1087 
1088 Datum
1090 {
1091  int64 arg1 = PG_GETARG_INT64(0);
1092  int32 arg2 = PG_GETARG_INT32(1);
1093 
1094  PG_RETURN_INT64(arg1 << arg2);
1095 }
1096 
1097 Datum
1099 {
1100  int64 arg1 = PG_GETARG_INT64(0);
1101  int32 arg2 = PG_GETARG_INT32(1);
1102 
1103  PG_RETURN_INT64(arg1 >> arg2);
1104 }
1105 
1106 /*----------------------------------------------------------
1107  * Conversion operators.
1108  *---------------------------------------------------------*/
1109 
1110 Datum
1112 {
1113  int32 arg = PG_GETARG_INT32(0);
1114 
1115  PG_RETURN_INT64((int64) arg);
1116 }
1117 
1118 Datum
1120 {
1121  int64 arg = PG_GETARG_INT64(0);
1122 
1123  if (unlikely(arg < PG_INT32_MIN) || unlikely(arg > PG_INT32_MAX))
1124  ereport(ERROR,
1125  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1126  errmsg("integer out of range")));
1127 
1128  PG_RETURN_INT32((int32) arg);
1129 }
1130 
1131 Datum
1133 {
1134  int16 arg = PG_GETARG_INT16(0);
1135 
1136  PG_RETURN_INT64((int64) arg);
1137 }
1138 
1139 Datum
1141 {
1142  int64 arg = PG_GETARG_INT64(0);
1143 
1144  if (unlikely(arg < PG_INT16_MIN) || unlikely(arg > PG_INT16_MAX))
1145  ereport(ERROR,
1146  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1147  errmsg("smallint out of range")));
1148 
1149  PG_RETURN_INT16((int16) arg);
1150 }
1151 
1152 Datum
1154 {
1155  int64 arg = PG_GETARG_INT64(0);
1156  float8 result;
1157 
1158  result = arg;
1159 
1160  PG_RETURN_FLOAT8(result);
1161 }
1162 
1163 /* dtoi8()
1164  * Convert float8 to 8-byte integer.
1165  */
1166 Datum
1168 {
1170  int64 result;
1171 
1172  /* Round arg to nearest integer (but it's still in float form) */
1173  arg = rint(arg);
1174 
1175  if (unlikely(arg < (double) PG_INT64_MIN) ||
1176  unlikely(arg > (double) PG_INT64_MAX) ||
1177  unlikely(isnan(arg)))
1178  ereport(ERROR,
1179  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1180  errmsg("bigint out of range")));
1181 
1182  result = (int64) arg;
1183 
1184  PG_RETURN_INT64(result);
1185 }
1186 
1187 Datum
1189 {
1190  int64 arg = PG_GETARG_INT64(0);
1191  float4 result;
1192 
1193  result = arg;
1194 
1195  PG_RETURN_FLOAT4(result);
1196 }
1197 
1198 /* ftoi8()
1199  * Convert float4 to 8-byte integer.
1200  */
1201 Datum
1203 {
1205  float8 darg;
1206 
1207  /* Round arg to nearest integer (but it's still in float form) */
1208  darg = rint(arg);
1209 
1210  if (unlikely(arg < (float4) PG_INT64_MIN) ||
1211  unlikely(arg > (float4) PG_INT64_MAX) ||
1212  unlikely(isnan(arg)))
1213  ereport(ERROR,
1214  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1215  errmsg("bigint out of range")));
1216 
1217  PG_RETURN_INT64((int64) darg);
1218 }
1219 
1220 Datum
1222 {
1223  int64 arg = PG_GETARG_INT64(0);
1224 
1225  if (unlikely(arg < 0) || unlikely(arg > PG_UINT32_MAX))
1226  ereport(ERROR,
1227  (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
1228  errmsg("OID out of range")));
1229 
1230  PG_RETURN_OID((Oid) arg);
1231 }
1232 
1233 Datum
1235 {
1236  Oid arg = PG_GETARG_OID(0);
1237 
1238  PG_RETURN_INT64((int64) arg);
1239 }
1240 
1241 /*
1242  * non-persistent numeric series generator
1243  */
1244 Datum
1246 {
1247  return generate_series_step_int8(fcinfo);
1248 }
1249 
1250 Datum
1252 {
1253  FuncCallContext *funcctx;
1254  generate_series_fctx *fctx;
1255  int64 result;
1256  MemoryContext oldcontext;
1257 
1258  /* stuff done only on the first call of the function */
1259  if (SRF_IS_FIRSTCALL())
1260  {
1261  int64 start = PG_GETARG_INT64(0);
1262  int64 finish = PG_GETARG_INT64(1);
1263  int64 step = 1;
1264 
1265  /* see if we were given an explicit step size */
1266  if (PG_NARGS() == 3)
1267  step = PG_GETARG_INT64(2);
1268  if (step == 0)
1269  ereport(ERROR,
1270  (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
1271  errmsg("step size cannot equal zero")));
1272 
1273  /* create a function context for cross-call persistence */
1274  funcctx = SRF_FIRSTCALL_INIT();
1275 
1276  /*
1277  * switch to memory context appropriate for multiple function calls
1278  */
1279  oldcontext = MemoryContextSwitchTo(funcctx->multi_call_memory_ctx);
1280 
1281  /* allocate memory for user context */
1282  fctx = (generate_series_fctx *) palloc(sizeof(generate_series_fctx));
1283 
1284  /*
1285  * Use fctx to keep state from call to call. Seed current with the
1286  * original start value
1287  */
1288  fctx->current = start;
1289  fctx->finish = finish;
1290  fctx->step = step;
1291 
1292  funcctx->user_fctx = fctx;
1293  MemoryContextSwitchTo(oldcontext);
1294  }
1295 
1296  /* stuff done on every call of the function */
1297  funcctx = SRF_PERCALL_SETUP();
1298 
1299  /*
1300  * get the saved state and use current as the result for this iteration
1301  */
1302  fctx = funcctx->user_fctx;
1303  result = fctx->current;
1304 
1305  if ((fctx->step > 0 && fctx->current <= fctx->finish) ||
1306  (fctx->step < 0 && fctx->current >= fctx->finish))
1307  {
1308  /*
1309  * Increment current in preparation for next iteration. If next-value
1310  * computation overflows, this is the final result.
1311  */
1312  if (pg_add_s64_overflow(fctx->current, fctx->step, &fctx->current))
1313  fctx->step = 0;
1314 
1315  /* do when there is more left to send */
1316  SRF_RETURN_NEXT(funcctx, Int64GetDatum(result));
1317  }
1318  else
1319  /* do when there is no more left */
1320  SRF_RETURN_DONE(funcctx);
1321 }
#define PG_GETARG_FLOAT8(n)
Definition: fmgr.h:246
signed short int16
Definition: c.h:283
Datum int8lt(PG_FUNCTION_ARGS)
Definition: int8.c:211
#define PG_RETURN_POINTER(x)
Definition: fmgr.h:321
Datum int8ge(PG_FUNCTION_ARGS)
Definition: int8.c:238
#define PG_GETARG_INT32(n)
Definition: fmgr.h:234
#define PG_RETURN_FLOAT4(x)
Definition: fmgr.h:325
#define PG_INT64_MAX
Definition: c.h:382
Datum int84ge(PG_FUNCTION_ARGS)
Definition: int8.c:295
Datum int82mul(PG_FUNCTION_ARGS)
Definition: int8.c:930
Datum generate_series_step_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1251
#define MAXINT8LEN
Definition: int8.c:27
Datum int82eq(PG_FUNCTION_ARGS)
Definition: int8.c:364
Datum int8xor(PG_FUNCTION_ARGS)
Definition: int8.c:1072
Datum int82ge(PG_FUNCTION_ARGS)
Definition: int8.c:409
Datum int48div(PG_FUNCTION_ARGS)
Definition: int8.c:883
static bool pg_sub_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:175
#define PG_RETURN_INT64(x)
Definition: fmgr.h:327
#define SRF_IS_FIRSTCALL()
Definition: funcapi.h:293
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:1076
Datum int8pl(PG_FUNCTION_ARGS)
Definition: int8.c:502
StringInfoData * StringInfo
Definition: stringinfo.h:43
#define PG_RETURN_FLOAT8(x)
Definition: fmgr.h:326
Datum generate_series_int8(PG_FUNCTION_ARGS)
Definition: int8.c:1245
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:314
Datum int84div(PG_FUNCTION_ARGS)
Definition: int8.c:802
#define PG_RETURN_INT16(x)
Definition: fmgr.h:316
static void pq_sendint64(StringInfo buf, int64 i)
Definition: pqformat.h:156
int errcode(int sqlerrcode)
Definition: elog.c:575
Datum int28div(PG_FUNCTION_ARGS)
Definition: int8.c:1025
Datum int8le(PG_FUNCTION_ARGS)
Definition: int8.c:229
Datum int8mi(PG_FUNCTION_ARGS)
Definition: int8.c:516
Datum int82pl(PG_FUNCTION_ARGS)
Definition: int8.c:902
#define PG_GETARG_POINTER(n)
Definition: fmgr.h:241
Datum int82mi(PG_FUNCTION_ARGS)
Definition: int8.c:916
#define PG_RETURN_BYTEA_P(x)
Definition: fmgr.h:330
#define PG_UINT32_MAX
Definition: c.h:380
unsigned int Oid
Definition: postgres_ext.h:31
bytea * pq_endtypsend(StringInfo buf)
Definition: pqformat.c:348
#define SRF_PERCALL_SETUP()
Definition: funcapi.h:297
Datum int48mi(PG_FUNCTION_ARGS)
Definition: int8.c:855
Datum i8tooid(PG_FUNCTION_ARGS)
Definition: int8.c:1221
Datum int48ge(PG_FUNCTION_ARGS)
Definition: int8.c:352
signed int int32
Definition: c.h:284
Datum int8larger(PG_FUNCTION_ARGS)
Definition: int8.c:736
Datum int8smaller(PG_FUNCTION_ARGS)
Definition: int8.c:748
Datum ftoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1202
#define SRF_RETURN_NEXT(_funcctx, _result)
Definition: funcapi.h:299
Datum int8inc_float8_float8(PG_FUNCTION_ARGS)
Definition: int8.c:723
Datum int48eq(PG_FUNCTION_ARGS)
Definition: int8.c:307
#define ERROR
Definition: elog.h:43
double float8
Definition: c.h:429
Datum int82le(PG_FUNCTION_ARGS)
Definition: int8.c:400
Datum int8and(PG_FUNCTION_ARGS)
Definition: int8.c:1054
Datum int28ge(PG_FUNCTION_ARGS)
Definition: int8.c:466
Datum int8eq(PG_FUNCTION_ARGS)
Definition: int8.c:193
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:530
#define PG_INT64_MIN
Definition: c.h:381
#define PG_GETARG_OID(n)
Definition: fmgr.h:240
Datum int8inc(PG_FUNCTION_ARGS)
Definition: int8.c:632
Datum dtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1167
Datum int8div(PG_FUNCTION_ARGS)
Definition: int8.c:544
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:1786
double rint(double x)
Definition: rint.c:22
#define PG_INT16_MIN
Definition: c.h:375
#define PG_INT32_MIN
Definition: c.h:378
#define PG_GETARG_FLOAT4(n)
Definition: fmgr.h:245
#define ereport(elevel, rest)
Definition: elog.h:122
Datum int48lt(PG_FUNCTION_ARGS)
Definition: int8.c:325
Datum int8um(PG_FUNCTION_ARGS)
Definition: int8.c:480
Datum int84le(PG_FUNCTION_ARGS)
Definition: int8.c:286
Datum int84mul(PG_FUNCTION_ARGS)
Definition: int8.c:788
signed char int8
Definition: c.h:282
Datum int8dec(PG_FUNCTION_ARGS)
Definition: int8.c:670
float float4
Definition: c.h:428
Datum int48pl(PG_FUNCTION_ARGS)
Definition: int8.c:841
Datum int8dec_any(PG_FUNCTION_ARGS)
Definition: int8.c:729
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:319
uintptr_t Datum
Definition: postgres.h:372
Datum int82div(PG_FUNCTION_ARGS)
Definition: int8.c:944
Datum int82(PG_FUNCTION_ARGS)
Definition: int8.c:1140
Datum int82lt(PG_FUNCTION_ARGS)
Definition: int8.c:382
#define PG_GETARG_INT16(n)
Definition: fmgr.h:236
Datum int84gt(PG_FUNCTION_ARGS)
Definition: int8.c:277
Datum int28ne(PG_FUNCTION_ARGS)
Definition: int8.c:430
Datum int8shr(PG_FUNCTION_ARGS)
Definition: int8.c:1098
static bool pg_add_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:149
Datum int28le(PG_FUNCTION_ARGS)
Definition: int8.c:457
int32 current
Definition: int.c:45
int32 finish
Definition: int.c:46
Datum int84pl(PG_FUNCTION_ARGS)
Definition: int8.c:760
Datum int8shl(PG_FUNCTION_ARGS)
Definition: int8.c:1089
static bool pg_mul_s64_overflow(int64 a, int64 b, int64 *result)
Definition: int.h:201
Datum int48mul(PG_FUNCTION_ARGS)
Definition: int8.c:869
Datum i8tod(PG_FUNCTION_ARGS)
Definition: int8.c:1153
#define PG_RETURN_CSTRING(x)
Definition: fmgr.h:322
MemoryContext multi_call_memory_ctx
Definition: funcapi.h:110
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:1011
Datum int8send(PG_FUNCTION_ARGS)
Definition: int8.c:174
int AggCheckCallContext(FunctionCallInfo fcinfo, MemoryContext *aggcontext)
Definition: nodeAgg.c:4127
#define PG_INT16_MAX
Definition: c.h:376
Datum int84eq(PG_FUNCTION_ARGS)
Definition: int8.c:250
#define PG_NARGS()
Definition: fmgr.h:168
Datum int8in(PG_FUNCTION_ARGS)
Definition: int8.c:135
void pg_lltoa(int64 value, char *a)
Definition: numutils.c:186
Datum int28lt(PG_FUNCTION_ARGS)
Definition: int8.c:439
Datum int8abs(PG_FUNCTION_ARGS)
Definition: int8.c:586
Datum int28(PG_FUNCTION_ARGS)
Definition: int8.c:1132
Datum int84(PG_FUNCTION_ARGS)
Definition: int8.c:1119
Datum i8tof(PG_FUNCTION_ARGS)
Definition: int8.c:1188
void * user_fctx
Definition: funcapi.h:91
Datum int84mi(PG_FUNCTION_ARGS)
Definition: int8.c:774
void * palloc(Size size)
Definition: mcxt.c:848
int errmsg(const char *fmt,...)
Definition: elog.c:797
Datum int8or(PG_FUNCTION_ARGS)
Definition: int8.c:1063
#define PG_INT32_MAX
Definition: c.h:379
Datum int48(PG_FUNCTION_ARGS)
Definition: int8.c:1111
Datum int28pl(PG_FUNCTION_ARGS)
Definition: int8.c:983
int64 pq_getmsgint64(StringInfo msg)
Definition: pqformat.c:455
void * arg
#define unlikely(x)
Definition: c.h:190
#define PG_GETARG_CSTRING(n)
Definition: fmgr.h:242
#define PG_FUNCTION_ARGS
Definition: fmgr.h:158
Datum int8inc_any(PG_FUNCTION_ARGS)
Definition: int8.c:717
Datum int48ne(PG_FUNCTION_ARGS)
Definition: int8.c:316
Datum int8not(PG_FUNCTION_ARGS)
Definition: int8.c:1081
Datum int28mi(PG_FUNCTION_ARGS)
Definition: int8.c:997
#define PG_GETARG_INT64(n)
Definition: fmgr.h:247
Datum int48le(PG_FUNCTION_ARGS)
Definition: int8.c:343
#define PG_RETURN_OID(x)
Definition: fmgr.h:320
Datum oidtoi8(PG_FUNCTION_ARGS)
Definition: int8.c:1234
long val
Definition: informix.c:689
Datum int8out(PG_FUNCTION_ARGS)
Definition: int8.c:148
#define PG_RETURN_NULL()
Definition: fmgr.h:305
Datum int8up(PG_FUNCTION_ARGS)
Definition: int8.c:494
Datum int8mod(PG_FUNCTION_ARGS)
Definition: int8.c:603
#define SRF_RETURN_DONE(_funcctx)
Definition: funcapi.h:317
bool scanint8(const char *str, bool errorOK, int64 *result)
Definition: int8.c:54
#define SRF_FIRSTCALL_INIT()
Definition: funcapi.h:295