3 -- Test int8 64-bit integers.
5 CREATE TABLE INT8_TBL(q1 int8, q2 int8);
6 INSERT INTO INT8_TBL VALUES(' 123 ',' 456');
7 INSERT INTO INT8_TBL VALUES('123 ','4567890123456789');
8 INSERT INTO INT8_TBL VALUES('4567890123456789','123');
9 INSERT INTO INT8_TBL VALUES(+4567890123456789,'4567890123456789');
10 INSERT INTO INT8_TBL VALUES('+4567890123456789','-4567890123456789');
12 INSERT INTO INT8_TBL(q1) VALUES (' ');
13 ERROR: invalid input syntax for type bigint: " "
14 LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' ');
16 INSERT INTO INT8_TBL(q1) VALUES ('xxx');
17 ERROR: invalid input syntax for type bigint: "xxx"
18 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('xxx');
20 INSERT INTO INT8_TBL(q1) VALUES ('3908203590239580293850293850329485');
21 ERROR: value "3908203590239580293850293850329485" is out of range for type bigint
22 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('39082035902395802938502938...
24 INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340329840934');
25 ERROR: value "-1204982019841029840928340329840934" is out of range for type bigint
26 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('-1204982019841029840928340...
28 INSERT INTO INT8_TBL(q1) VALUES ('- 123');
29 ERROR: invalid input syntax for type bigint: "- 123"
30 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('- 123');
32 INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
33 ERROR: invalid input syntax for type bigint: " 345 5"
34 LINE 1: INSERT INTO INT8_TBL(q1) VALUES (' 345 5');
36 INSERT INTO INT8_TBL(q1) VALUES ('');
37 ERROR: invalid input syntax for type bigint: ""
38 LINE 1: INSERT INTO INT8_TBL(q1) VALUES ('');
40 SELECT * FROM INT8_TBL;
42 ------------------+-------------------
44 123 | 4567890123456789
45 4567890123456789 | 123
46 4567890123456789 | 4567890123456789
47 4567890123456789 | -4567890123456789
51 SELECT * FROM INT8_TBL WHERE q2 = 4567890123456789;
53 ------------------+------------------
54 123 | 4567890123456789
55 4567890123456789 | 4567890123456789
58 SELECT * FROM INT8_TBL WHERE q2 <> 4567890123456789;
60 ------------------+-------------------
62 4567890123456789 | 123
63 4567890123456789 | -4567890123456789
66 SELECT * FROM INT8_TBL WHERE q2 < 4567890123456789;
68 ------------------+-------------------
70 4567890123456789 | 123
71 4567890123456789 | -4567890123456789
74 SELECT * FROM INT8_TBL WHERE q2 > 4567890123456789;
79 SELECT * FROM INT8_TBL WHERE q2 <= 4567890123456789;
81 ------------------+-------------------
83 123 | 4567890123456789
84 4567890123456789 | 123
85 4567890123456789 | 4567890123456789
86 4567890123456789 | -4567890123456789
89 SELECT * FROM INT8_TBL WHERE q2 >= 4567890123456789;
91 ------------------+------------------
92 123 | 4567890123456789
93 4567890123456789 | 4567890123456789
97 SELECT * FROM INT8_TBL WHERE q2 = 456;
103 SELECT * FROM INT8_TBL WHERE q2 <> 456;
105 ------------------+-------------------
106 123 | 4567890123456789
107 4567890123456789 | 123
108 4567890123456789 | 4567890123456789
109 4567890123456789 | -4567890123456789
112 SELECT * FROM INT8_TBL WHERE q2 < 456;
114 ------------------+-------------------
115 4567890123456789 | 123
116 4567890123456789 | -4567890123456789
119 SELECT * FROM INT8_TBL WHERE q2 > 456;
121 ------------------+------------------
122 123 | 4567890123456789
123 4567890123456789 | 4567890123456789
126 SELECT * FROM INT8_TBL WHERE q2 <= 456;
128 ------------------+-------------------
130 4567890123456789 | 123
131 4567890123456789 | -4567890123456789
134 SELECT * FROM INT8_TBL WHERE q2 >= 456;
136 ------------------+------------------
138 123 | 4567890123456789
139 4567890123456789 | 4567890123456789
143 SELECT * FROM INT8_TBL WHERE 123 = q1;
145 -----+------------------
147 123 | 4567890123456789
150 SELECT * FROM INT8_TBL WHERE 123 <> q1;
152 ------------------+-------------------
153 4567890123456789 | 123
154 4567890123456789 | 4567890123456789
155 4567890123456789 | -4567890123456789
158 SELECT * FROM INT8_TBL WHERE 123 < q1;
160 ------------------+-------------------
161 4567890123456789 | 123
162 4567890123456789 | 4567890123456789
163 4567890123456789 | -4567890123456789
166 SELECT * FROM INT8_TBL WHERE 123 > q1;
171 SELECT * FROM INT8_TBL WHERE 123 <= q1;
173 ------------------+-------------------
175 123 | 4567890123456789
176 4567890123456789 | 123
177 4567890123456789 | 4567890123456789
178 4567890123456789 | -4567890123456789
181 SELECT * FROM INT8_TBL WHERE 123 >= q1;
183 -----+------------------
185 123 | 4567890123456789
189 SELECT * FROM INT8_TBL WHERE q2 = '456'::int2;
195 SELECT * FROM INT8_TBL WHERE q2 <> '456'::int2;
197 ------------------+-------------------
198 123 | 4567890123456789
199 4567890123456789 | 123
200 4567890123456789 | 4567890123456789
201 4567890123456789 | -4567890123456789
204 SELECT * FROM INT8_TBL WHERE q2 < '456'::int2;
206 ------------------+-------------------
207 4567890123456789 | 123
208 4567890123456789 | -4567890123456789
211 SELECT * FROM INT8_TBL WHERE q2 > '456'::int2;
213 ------------------+------------------
214 123 | 4567890123456789
215 4567890123456789 | 4567890123456789
218 SELECT * FROM INT8_TBL WHERE q2 <= '456'::int2;
220 ------------------+-------------------
222 4567890123456789 | 123
223 4567890123456789 | -4567890123456789
226 SELECT * FROM INT8_TBL WHERE q2 >= '456'::int2;
228 ------------------+------------------
230 123 | 4567890123456789
231 4567890123456789 | 4567890123456789
235 SELECT * FROM INT8_TBL WHERE '123'::int2 = q1;
237 -----+------------------
239 123 | 4567890123456789
242 SELECT * FROM INT8_TBL WHERE '123'::int2 <> q1;
244 ------------------+-------------------
245 4567890123456789 | 123
246 4567890123456789 | 4567890123456789
247 4567890123456789 | -4567890123456789
250 SELECT * FROM INT8_TBL WHERE '123'::int2 < q1;
252 ------------------+-------------------
253 4567890123456789 | 123
254 4567890123456789 | 4567890123456789
255 4567890123456789 | -4567890123456789
258 SELECT * FROM INT8_TBL WHERE '123'::int2 > q1;
263 SELECT * FROM INT8_TBL WHERE '123'::int2 <= q1;
265 ------------------+-------------------
267 123 | 4567890123456789
268 4567890123456789 | 123
269 4567890123456789 | 4567890123456789
270 4567890123456789 | -4567890123456789
273 SELECT * FROM INT8_TBL WHERE '123'::int2 >= q1;
275 -----+------------------
277 123 | 4567890123456789
280 SELECT q1 AS plus, -q1 AS minus FROM INT8_TBL;
282 ------------------+-------------------
285 4567890123456789 | -4567890123456789
286 4567890123456789 | -4567890123456789
287 4567890123456789 | -4567890123456789
290 SELECT q1, q2, q1 + q2 AS plus FROM INT8_TBL;
292 ------------------+-------------------+------------------
294 123 | 4567890123456789 | 4567890123456912
295 4567890123456789 | 123 | 4567890123456912
296 4567890123456789 | 4567890123456789 | 9135780246913578
297 4567890123456789 | -4567890123456789 | 0
300 SELECT q1, q2, q1 - q2 AS minus FROM INT8_TBL;
302 ------------------+-------------------+-------------------
304 123 | 4567890123456789 | -4567890123456666
305 4567890123456789 | 123 | 4567890123456666
306 4567890123456789 | 4567890123456789 | 0
307 4567890123456789 | -4567890123456789 | 9135780246913578
310 SELECT q1, q2, q1 * q2 AS multiply FROM INT8_TBL;
311 ERROR: bigint out of range
312 SELECT q1, q2, q1 * q2 AS multiply FROM INT8_TBL
313 WHERE q1 < 1000 or (q2 > 0 and q2 < 1000);
315 ------------------+------------------+--------------------
317 123 | 4567890123456789 | 561850485185185047
318 4567890123456789 | 123 | 561850485185185047
321 SELECT q1, q2, q1 / q2 AS divide, q1 % q2 AS mod FROM INT8_TBL;
322 q1 | q2 | divide | mod
323 ------------------+-------------------+----------------+-----
325 123 | 4567890123456789 | 0 | 123
326 4567890123456789 | 123 | 37137318076884 | 57
327 4567890123456789 | 4567890123456789 | 1 | 0
328 4567890123456789 | -4567890123456789 | -1 | 0
331 SELECT q1, float8(q1) FROM INT8_TBL;
333 ------------------+-----------------------
336 4567890123456789 | 4.567890123456789e+15
337 4567890123456789 | 4.567890123456789e+15
338 4567890123456789 | 4.567890123456789e+15
341 SELECT q2, float8(q2) FROM INT8_TBL;
343 -------------------+------------------------
345 4567890123456789 | 4.567890123456789e+15
347 4567890123456789 | 4.567890123456789e+15
348 -4567890123456789 | -4.567890123456789e+15
351 SELECT 37 + q1 AS plus4 FROM INT8_TBL;
361 SELECT 37 - q1 AS minus4 FROM INT8_TBL;
371 SELECT 2 * q1 AS "twice int4" FROM INT8_TBL;
381 SELECT q1 * 2 AS "twice int4" FROM INT8_TBL;
392 SELECT q1 + 42::int4 AS "8plus4", q1 - 42::int4 AS "8minus4", q1 * 42::int4 AS "8mul4", q1 / 42::int4 AS "8div4" FROM INT8_TBL;
393 8plus4 | 8minus4 | 8mul4 | 8div4
394 ------------------+------------------+--------------------+-----------------
397 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
398 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
399 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
403 SELECT 246::int4 + q1 AS "4plus8", 246::int4 - q1 AS "4minus8", 246::int4 * q1 AS "4mul8", 246::int4 / q1 AS "4div8" FROM INT8_TBL;
404 4plus8 | 4minus8 | 4mul8 | 4div8
405 ------------------+-------------------+---------------------+-------
406 369 | 123 | 30258 | 2
407 369 | 123 | 30258 | 2
408 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
409 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
410 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
414 SELECT q1 + 42::int2 AS "8plus2", q1 - 42::int2 AS "8minus2", q1 * 42::int2 AS "8mul2", q1 / 42::int2 AS "8div2" FROM INT8_TBL;
415 8plus2 | 8minus2 | 8mul2 | 8div2
416 ------------------+------------------+--------------------+-----------------
419 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
420 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
421 4567890123456831 | 4567890123456747 | 191851385185185138 | 108759288653733
425 SELECT 246::int2 + q1 AS "2plus8", 246::int2 - q1 AS "2minus8", 246::int2 * q1 AS "2mul8", 246::int2 / q1 AS "2div8" FROM INT8_TBL;
426 2plus8 | 2minus8 | 2mul8 | 2div8
427 ------------------+-------------------+---------------------+-------
428 369 | 123 | 30258 | 2
429 369 | 123 | 30258 | 2
430 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
431 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
432 4567890123457035 | -4567890123456543 | 1123700970370370094 | 0
435 SELECT q2, abs(q2) FROM INT8_TBL;
437 -------------------+------------------
439 4567890123456789 | 4567890123456789
441 4567890123456789 | 4567890123456789
442 -4567890123456789 | 4567890123456789
445 SELECT min(q1), min(q2) FROM INT8_TBL;
447 -----+-------------------
448 123 | -4567890123456789
451 SELECT max(q1), max(q2) FROM INT8_TBL;
453 ------------------+------------------
454 4567890123456789 | 4567890123456789
459 SELECT to_char(q1, '9G999G999G999G999G999'), to_char(q2, '9,999,999,999,999,999')
462 ------------------------+------------------------
464 123 | 4,567,890,123,456,789
465 4,567,890,123,456,789 | 123
466 4,567,890,123,456,789 | 4,567,890,123,456,789
467 4,567,890,123,456,789 | -4,567,890,123,456,789
470 SELECT to_char(q1, '9G999G999G999G999G999D999G999'), to_char(q2, '9,999,999,999,999,999.999,999')
473 --------------------------------+--------------------------------
474 123.000,000 | 456.000,000
475 123.000,000 | 4,567,890,123,456,789.000,000
476 4,567,890,123,456,789.000,000 | 123.000,000
477 4,567,890,123,456,789.000,000 | 4,567,890,123,456,789.000,000
478 4,567,890,123,456,789.000,000 | -4,567,890,123,456,789.000,000
481 SELECT to_char( (q1 * -1), '9999999999999999PR'), to_char( (q2 * -1), '9999999999999999.999PR')
484 --------------------+------------------------
486 <123> | <4567890123456789.000>
487 <4567890123456789> | <123.000>
488 <4567890123456789> | <4567890123456789.000>
489 <4567890123456789> | 4567890123456789.000
492 SELECT to_char( (q1 * -1), '9999999999999999S'), to_char( (q2 * -1), 'S9999999999999999')
495 -------------------+-------------------
497 123- | -4567890123456789
498 4567890123456789- | -123
499 4567890123456789- | -4567890123456789
500 4567890123456789- | +4567890123456789
503 SELECT to_char(q2, 'MI9999999999999999') FROM INT8_TBL;
513 SELECT to_char(q2, 'FMS9999999999999999') FROM INT8_TBL;
523 SELECT to_char(q2, 'FM9999999999999999THPR') FROM INT8_TBL;
533 SELECT to_char(q2, 'SG9999999999999999th') FROM INT8_TBL;
535 ---------------------
543 SELECT to_char(q2, '0999999999999999') FROM INT8_TBL;
553 SELECT to_char(q2, 'S0999999999999999') FROM INT8_TBL;
563 SELECT to_char(q2, 'FM0999999999999999') FROM INT8_TBL;
573 SELECT to_char(q2, 'FM9999999999999999.000') FROM INT8_TBL;
575 -----------------------
580 -4567890123456789.000
583 SELECT to_char(q2, 'L9999999999999999.000') FROM INT8_TBL;
585 ------------------------
590 -4567890123456789.000
593 SELECT to_char(q2, 'FM9999999999999999.999') FROM INT8_TBL;
603 SELECT to_char(q2, 'S 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 9 . 9 9 9') FROM INT8_TBL;
605 -------------------------------------------
607 +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
609 +4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
610 -4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 . 0 0 0
613 SELECT to_char(q2, E'99999 "text" 9999 "9999" 999 "\\"text between quote marks\\"" 9999') FROM INT8_TBL;
615 -----------------------------------------------------------
616 text 9999 "text between quote marks" 456
617 45678 text 9012 9999 345 "text between quote marks" 6789
618 text 9999 "text between quote marks" 123
619 45678 text 9012 9999 345 "text between quote marks" 6789
620 -45678 text 9012 9999 345 "text between quote marks" 6789
623 SELECT to_char(q2, '999999SG9999999999') FROM INT8_TBL;
633 -- check min/max values and overflow behavior
634 select '-9223372036854775808'::int8;
636 ----------------------
640 select '-9223372036854775809'::int8;
641 ERROR: value "-9223372036854775809" is out of range for type bigint
642 LINE 1: select '-9223372036854775809'::int8;
644 select '9223372036854775807'::int8;
646 ---------------------
650 select '9223372036854775808'::int8;
651 ERROR: value "9223372036854775808" is out of range for type bigint
652 LINE 1: select '9223372036854775808'::int8;
654 select -('-9223372036854775807'::int8);
656 ---------------------
660 select -('-9223372036854775808'::int8);
661 ERROR: bigint out of range
662 select '9223372036854775800'::int8 + '9223372036854775800'::int8;
663 ERROR: bigint out of range
664 select '-9223372036854775800'::int8 + '-9223372036854775800'::int8;
665 ERROR: bigint out of range
666 select '9223372036854775800'::int8 - '-9223372036854775800'::int8;
667 ERROR: bigint out of range
668 select '-9223372036854775800'::int8 - '9223372036854775800'::int8;
669 ERROR: bigint out of range
670 select '9223372036854775800'::int8 * '9223372036854775800'::int8;
671 ERROR: bigint out of range
672 select '9223372036854775800'::int8 / '0'::int8;
673 ERROR: division by zero
674 select '9223372036854775800'::int8 % '0'::int8;
675 ERROR: division by zero
676 select abs('-9223372036854775808'::int8);
677 ERROR: bigint out of range
678 select '9223372036854775800'::int8 + '100'::int4;
679 ERROR: bigint out of range
680 select '-9223372036854775800'::int8 - '100'::int4;
681 ERROR: bigint out of range
682 select '9223372036854775800'::int8 * '100'::int4;
683 ERROR: bigint out of range
684 select '100'::int4 + '9223372036854775800'::int8;
685 ERROR: bigint out of range
686 select '-100'::int4 - '9223372036854775800'::int8;
687 ERROR: bigint out of range
688 select '100'::int4 * '9223372036854775800'::int8;
689 ERROR: bigint out of range
690 select '9223372036854775800'::int8 + '100'::int2;
691 ERROR: bigint out of range
692 select '-9223372036854775800'::int8 - '100'::int2;
693 ERROR: bigint out of range
694 select '9223372036854775800'::int8 * '100'::int2;
695 ERROR: bigint out of range
696 select '-9223372036854775808'::int8 / '0'::int2;
697 ERROR: division by zero
698 select '100'::int2 + '9223372036854775800'::int8;
699 ERROR: bigint out of range
700 select '-100'::int2 - '9223372036854775800'::int8;
701 ERROR: bigint out of range
702 select '100'::int2 * '9223372036854775800'::int8;
703 ERROR: bigint out of range
704 select '100'::int2 / '0'::int8;
705 ERROR: division by zero
706 SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 = 456;
712 SELECT CAST(q1 AS int4) FROM int8_tbl WHERE q2 <> 456;
713 ERROR: integer out of range
714 SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 = 456;
720 SELECT CAST(q1 AS int2) FROM int8_tbl WHERE q2 <> 456;
721 ERROR: smallint out of range
722 SELECT CAST('42'::int2 AS int8), CAST('-37'::int2 AS int8);
728 SELECT CAST(q1 AS float4), CAST(q2 AS float8) FROM INT8_TBL;
730 -------------+------------------------
732 123 | 4.567890123456789e+15
734 4.56789e+15 | 4.567890123456789e+15
735 4.56789e+15 | -4.567890123456789e+15
738 SELECT CAST('36854775807.0'::float4 AS int8);
744 SELECT CAST('922337203685477580700.0'::float8 AS int8);
745 ERROR: bigint out of range
746 SELECT CAST(q1 AS oid) FROM INT8_TBL;
747 ERROR: OID out of range
748 SELECT oid::int8 FROM pg_class WHERE relname = 'pg_class';
755 SELECT q1, q2, q1 & q2 AS "and", q1 | q2 AS "or", q1 # q2 AS "xor", ~q1 AS "not" FROM INT8_TBL;
756 q1 | q2 | and | or | xor | not
757 ------------------+-------------------+------------------+------------------+------------------+-------------------
758 123 | 456 | 72 | 507 | 435 | -124
759 123 | 4567890123456789 | 17 | 4567890123456895 | 4567890123456878 | -124
760 4567890123456789 | 123 | 17 | 4567890123456895 | 4567890123456878 | -4567890123456790
761 4567890123456789 | 4567890123456789 | 4567890123456789 | 4567890123456789 | 0 | -4567890123456790
762 4567890123456789 | -4567890123456789 | 1 | -1 | -2 | -4567890123456790
765 SELECT q1, q1 << 2 AS "shl", q1 >> 3 AS "shr" FROM INT8_TBL;
767 ------------------+-------------------+-----------------
770 4567890123456789 | 18271560493827156 | 570986265432098
771 4567890123456789 | 18271560493827156 | 570986265432098
772 4567890123456789 | 18271560493827156 | 570986265432098
776 SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8);
792 SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 0);
793 ERROR: step size cannot equal zero
794 SELECT * FROM generate_series('+4567890123456789'::int8, '+4567890123456799'::int8, 2);
806 SELECT (-1::int8<<63)::text;
808 ----------------------
812 SELECT ((-1::int8<<63)+1)::text;
814 ----------------------
818 -- check sane handling of INT64_MIN overflow cases
819 SELECT (-9223372036854775808)::int8 * (-1)::int8;
820 ERROR: bigint out of range
821 SELECT (-9223372036854775808)::int8 / (-1)::int8;
822 ERROR: bigint out of range
823 SELECT (-9223372036854775808)::int8 % (-1)::int8;
829 SELECT (-9223372036854775808)::int8 * (-1)::int4;
830 ERROR: bigint out of range
831 SELECT (-9223372036854775808)::int8 / (-1)::int4;
832 ERROR: bigint out of range
833 SELECT (-9223372036854775808)::int8 % (-1)::int4;
839 SELECT (-9223372036854775808)::int8 * (-1)::int2;
840 ERROR: bigint out of range
841 SELECT (-9223372036854775808)::int8 / (-1)::int2;
842 ERROR: bigint out of range
843 SELECT (-9223372036854775808)::int8 % (-1)::int2;
849 -- check rounding when casting from float
850 SELECT x, x::int8 AS int8_value
851 FROM (VALUES (-2.5::float8),
869 -- check rounding when casting from numeric
870 SELECT x, x::int8 AS int8_value
871 FROM (VALUES (-2.5::numeric),
877 (2.5::numeric)) t(x);
890 SELECT a, b, gcd(a, b), gcd(a, -b), gcd(b, a), gcd(-b, a)
891 FROM (VALUES (0::int8, 0::int8),
892 (0::int8, 29893644334::int8),
893 (288484263558::int8, 29893644334::int8),
894 (-288484263558::int8, 29893644334::int8),
895 ((-9223372036854775808)::int8, 1::int8),
896 ((-9223372036854775808)::int8, 9223372036854775807::int8),
897 ((-9223372036854775808)::int8, 4611686018427387904::int8)) AS v(a, b);
898 a | b | gcd | gcd | gcd | gcd
899 ----------------------+---------------------+---------------------+---------------------+---------------------+---------------------
900 0 | 0 | 0 | 0 | 0 | 0
901 0 | 29893644334 | 29893644334 | 29893644334 | 29893644334 | 29893644334
902 288484263558 | 29893644334 | 6835958 | 6835958 | 6835958 | 6835958
903 -288484263558 | 29893644334 | 6835958 | 6835958 | 6835958 | 6835958
904 -9223372036854775808 | 1 | 1 | 1 | 1 | 1
905 -9223372036854775808 | 9223372036854775807 | 1 | 1 | 1 | 1
906 -9223372036854775808 | 4611686018427387904 | 4611686018427387904 | 4611686018427387904 | 4611686018427387904 | 4611686018427387904
909 SELECT gcd((-9223372036854775808)::int8, 0::int8); -- overflow
910 ERROR: bigint out of range
911 SELECT gcd((-9223372036854775808)::int8, (-9223372036854775808)::int8); -- overflow
912 ERROR: bigint out of range
914 SELECT a, b, lcm(a, b), lcm(a, -b), lcm(b, a), lcm(-b, a)
915 FROM (VALUES (0::int8, 0::int8),
916 (0::int8, 29893644334::int8),
917 (29893644334::int8, 29893644334::int8),
918 (288484263558::int8, 29893644334::int8),
919 (-288484263558::int8, 29893644334::int8),
920 ((-9223372036854775808)::int8, 0::int8)) AS v(a, b);
921 a | b | lcm | lcm | lcm | lcm
922 ----------------------+-------------+------------------+------------------+------------------+------------------
923 0 | 0 | 0 | 0 | 0 | 0
924 0 | 29893644334 | 0 | 0 | 0 | 0
925 29893644334 | 29893644334 | 29893644334 | 29893644334 | 29893644334 | 29893644334
926 288484263558 | 29893644334 | 1261541684539134 | 1261541684539134 | 1261541684539134 | 1261541684539134
927 -288484263558 | 29893644334 | 1261541684539134 | 1261541684539134 | 1261541684539134 | 1261541684539134
928 -9223372036854775808 | 0 | 0 | 0 | 0 | 0
931 SELECT lcm((-9223372036854775808)::int8, 1::int8); -- overflow
932 ERROR: bigint out of range
933 SELECT lcm(9223372036854775807::int8, 9223372036854775806::int8); -- overflow
934 ERROR: bigint out of range