-
Notifications
You must be signed in to change notification settings - Fork 3.9k
/
Copy pathbuiltin_function
2059 lines (1636 loc) · 39.3 KB
/
builtin_function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# LogicTest: local local-opt local-parallel-stmts fakedist fakedist-metadata fakedist-opt
statement ok
CREATE TABLE foo (a int)
statement ok
INSERT INTO foo (a) VALUES (1)
query error unknown function: foo.bar
SELECT foo.bar()
query error unknown function: defaults
SELECT defaults()
query II colnames
SELECT length('roach7'), length(b'roach77')
----
length length
6 7
query IIIIII
SELECT length('Hello, 世界'), length(b'Hello, 世界'),
char_length('Hello, 世界'), char_length(b'Hello, 世界'),
character_length('Hello, 世界'), character_length(b'Hello, 世界')
----
9 13 9 13 9 13
statement error unknown signature: length\(int\)
SELECT length(23)
query III
SELECT octet_length('Hello'), octet_length('世界'), octet_length(b'世界')
----
5 6 6
query III
SELECT bit_length('Hello'), bit_length('世界'), bit_length(b'世界')
----
40 48 48
query TTTTTTTT
SELECT quote_ident('abc'), quote_ident('ab.c'), quote_ident('ab"c'), quote_ident('世界'),
quote_ident('array'), -- reserved keyword
quote_ident('family'), -- type/func name keyword
quote_ident('bigint'), -- col name keyword
quote_ident('alter') -- unreserved keyword
----
abc "ab.c" "ab""c" 世界 "array" "family" "bigint" alter
query TTTT
SELECT quote_literal('abc'), quote_literal('ab''c'), quote_literal('ab"c'), quote_literal(e'ab\nc')
----
'abc' e'ab\'c' 'ab"c' e'ab\nc'
query TTTTTTTT
SELECT
quote_literal(123::string), quote_nullable(123::string),
quote_literal(123), quote_nullable(123),
quote_literal(true), quote_nullable(true),
quote_literal(123.3), quote_nullable(123.3)
----
'123' '123' '123' '123' 'true' 'true' '123.3' '123.3'
query TTTTTT
SELECT
quote_literal('1d'::interval), quote_nullable('1d'::interval),
quote_literal('2018-06-11 12:13:14'::timestamp), quote_nullable('2018-06-11 12:13:14'::timestamp),
quote_literal('2018-06-11'::date), quote_nullable('2018-06-11'::date)
----
'1d' '1d' '2018-06-11 12:13:14+00:00' '2018-06-11 12:13:14+00:00' '2018-06-11' '2018-06-11'
query TTBB
SELECT
quote_literal(null::int), quote_nullable(null::int),
quote_literal(null::int) IS NULL, quote_nullable(null::int) IS NULL
----
NULL NULL true false
# Check that quote_literal is properly sensitive to bytea_output.
query TT
SELECT quote_literal(b'abc'), quote_nullable(b'abc')
----
e'\\x616263' e'\\x616263'
statement ok
SET bytea_output = 'escape'
query TT
SELECT quote_literal(b'abc'), quote_nullable(b'abc')
----
'abc' 'abc'
statement ok
RESET bytea_output
query T colnames
SELECT upper('roacH7')
----
upper
ROACH7
statement error unknown signature: upper\(decimal\)
SELECT upper(2.2)
query T colnames
SELECT lower('RoacH7')
----
lower
roach7
statement error unknown signature: lower\(int\)
SELECT lower(32)
# Multiplying by zero so the result is deterministic.
query R
SELECT random() * 0.0
----
0
# Concatenating 'empty' because the empty string doesn't work in these tests.
query T
SELECT concat() || 'empty'
----
empty
query T
SELECT concat('RoacH', NULL)
----
RoacH
statement error unknown signature: concat\(string, bool, decimal, bool\)
SELECT concat('RoacH', false, 64.532, TRUE)
query T
SELECT substr('RoacH', 2, 3)
----
oac
query T
SELECT substring('RoacH', 2, 3)
----
oac
query T
SELECT substring('💩oacH', 2, 3)
----
oac
query T
SELECT substring('RoacH' from 2 for 3)
----
oac
query T
SELECT substring('RoacH' for 3 from 2)
----
oac
query T
SELECT substr('RoacH', 2)
----
oacH
query T
SELECT substr('💩oacH', 2)
----
oacH
query T
SELECT substring('RoacH' from 2)
----
oacH
query T
SELECT substr('RoacH', -2)
----
RoacH
query T
SELECT substr('RoacH', -2, 4)
----
R
query T
SELECT substr('12345', 2, 77)
----
2345
query T
SELECT substr('12345', -2, 77)
----
12345
statement error substr\(\): negative substring length -1 not allowed
SELECT substr('12345', 2, -1)
query T
SELECT substr('string', 4827075662841736053, 5123273972570225659) || 'empty'
----
empty
query T
SELECT substring('12345' for 3)
----
123
query T
SELECT substring('foobar' from 'o.b')
----
oob
query T
SELECT substring('f(oabaroob' from '\(o(.)b')
----
a
query T
SELECT substring('f(oabaroob' from '+(o(.)b' for '+')
----
a
query error substring\(\): error parsing regexp: missing closing \): `\\\\\(o\(.\)b`
SELECT substring('f(oabaroob' from '\(o(.)b' for '+')
query error unknown signature: substring\(\)
SELECT substring()
query error unknown signature: concat_ws\(\)
SELECT concat_ws()
query T
SELECT concat_ws(NULL::STRING, 'a', 'b')
----
NULL
query T
SELECT concat_ws(',', 'abcde', NULL)
----
abcde
query T
SELECT concat_ws(',', 'abcde', '2')
----
abcde,2
statement error unknown signature: concat_ws\(string, string, int, unknown, int\)
SELECT concat_ws(',', 'abcde', 2, NULL, 22)
query T
SELECT split_part('abc~@~def~@~ghi', '~@~', 2)
----
def
query T
SELECT repeat('Pg', 4)
----
PgPgPgPg
query T
SELECT repeat('Pg', -1) || 'empty'
----
empty
statement error pq: repeat\(\): .* memory budget exceeded
SELECT repeat('s', 9223372036854775807)
# Regression for #19035.
statement error pq: repeat\(\): requested length too large
SELECT repeat('1234567890'::string, 6978072892806141784::int)
query I
SELECT ascii('x')
----
120
query I
select ascii('禅')
----
31109
query error ascii\(\): the input string must not be empty
select ascii('')
query T
select chr(122)
----
z
query T
select chr(ascii('Z'))
----
Z
query T
select chr(31109)
----
禅
query error chr\(\): input value must be >= 0
SELECT chr(-1)
query T
SELECT md5('abc')
----
900150983cd24fb0d6963f7d28e17f72
query T
SELECT sha1('abc')
----
a9993e364706816aba3e25717850c26c9cd0d89d
query T
SELECT sha256('abc')
----
ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad
query IIII
SELECT fnv32('abc'), fnv32a('abc'), fnv64('abc'), fnv64a('abc')
----
1134309195 440920331 -2820157060406071861 -1792535898324117685
query II
SELECT crc32ieee('abc'), crc32c('abc')
----
891568578 910901175
# Regression tests for #29754
query T
SELECT md5(NULL::STRING)
----
NULL
query T
SELECT md5('')
----
d41d8cd98f00b204e9800998ecf8427e
query T
SELECT md5(NULL::STRING, NULL::STRING)
----
NULL
query T
SELECT sha1(NULL::STRING)
----
NULL
query T
SELECT sha256(NULL::STRING)
----
NULL
query T
SELECT sha512(NULL::STRING, NULL::STRING)
----
NULL
query T
SELECT fnv32(NULL::STRING)
----
NULL
query T
SELECT to_hex(2147483647)
----
7fffffff
query I
SELECT strpos('high', 'a')
----
0
query I
SELECT strpos('high', 'ig')
----
2
query I
SELECT strpos('💩high', 'ig')
----
3
query I
SELECT position('ig' in 'high')
----
2
query I
SELECT position('a' in 'high')
----
0
query error unknown signature: strpos\(\)
SELECT position()
query T
SELECT overlay('123456789' placing 'xxxx' from 3)
----
12xxxx789
query T
SELECT overlay('123456789' placing 'xxxx' from 3 for 2)
----
12xxxx56789
query T
SELECT overlay('123456789' placing 'xxxx' from 3 for 6)
----
12xxxx9
query T
SELECT overlay('123456789' placing 'xxxx' from 15 for 6)
----
123456789xxxx
query T
SELECT overlay('123456789' placing 'xxxx' from 3 for 10)
----
12xxxx
query T
SELECT overlay('123456789' placing 'xxxx' from 3 for -1)
----
12xxxx23456789
query T
SELECT overlay('123456789' placing 'xxxx' from 3 for -8)
----
12xxxx123456789
query T
SELECT overlay('💩123456789' placing 'xxxxÂ' from 3 for 3)
----
💩1xxxxÂ56789
query error non-positive substring length not allowed: -1
SELECT overlay('123456789' placing 'xxxx' from -1 for 6)
query T
SELECT btrim('xyxtrimyyx', 'xy')
----
trim
query T
SELECT trim('xy' from 'xyxtrimyyx')
----
trim
query T
SELECT trim(both 'xy' from 'xyxtrimyyx')
----
trim
query T
SELECT 'a' || btrim(' postgres ') || 'b'
----
apostgresb
query T
SELECT ltrim('zzzytrimxyz', 'xyz')
----
trimxyz
query T
SELECT trim(leading 'xyz' from 'zzzytrimxyz')
----
trimxyz
query T
SELECT ltrim(' trimxyz')
----
trimxyz
query T
SELECT trim(leading ' trimxyz')
----
trimxyz
query T
SELECT trim(leading from ' trimxyz')
----
trimxyz
query T
SELECT rtrim('xyzzzzytrimxyz', 'xyz')
----
xyzzzzytrim
query T
SELECT trim(trailing 'xyz' from 'xyzzzzytrimxyz')
----
xyzzzzytrim
query T
SELECT 'a' || rtrim(' zzzytrimxyz ')
----
a zzzytrimxyz
query T
SELECT reverse('abcde')
----
edcba
query T
SELECT reverse('世界')
----
界世
query T
SELECT replace('abcdefabcdef', 'cd', 'XX')
----
abXXefabXXef
query T
SELECT replace(initcap('hi THOMAS'), ' ', '')
----
HiThomas
query T
SELECT initcap('THOMAS')
----
Thomas
query T
SELECT left('💩abcde'::bytes, 2)
----
[240 159]
query T
SELECT right('abcde💩'::bytes, 2)
----
[146 169]
query T
SELECT left('💩abcde', 2)
----
💩a
query T
SELECT right('abcde💩', 2)
----
e💩
query RRRIIR
SELECT abs(-1.2::float), abs(1.2::float), abs(-0.0::float), abs(0), abs(1), abs(-1.2121::decimal)
----
1.2 1.2 0 0 1 1.2121
query R
SELECT abs(NULL)
----
NULL
query error abs\(\): abs of min integer value \(-9223372036854775808\) not defined
SELECT abs(-9223372036854775808)
query I
SELECT abs(-9223372036854775807)
----
9223372036854775807
query B
SELECT abs(sin(pi())) < 1e-12
----
true
subtest standard_float_digits
query RR
SELECT acos(-0.5), round(acos(0.5), 15)
----
2.0943951023932 1.0471975511966
query RR
SELECT cot(-0.5), cot(0.5)
----
-1.83048772171245 1.83048772171245
query RRR
SELECT asin(-0.5), asin(0.5), asin(1.5)
----
-0.523598775598299 0.523598775598299 NaN
query RR
SELECT atan(-0.5), atan(0.5)
----
-0.463647609000806 0.463647609000806
query RR
SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0)
----
-1.10714871779409 1.10714871779409
query RRR
SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal)
----
-1 3 2.6823725926296729544
query RRRRR
SELECT ceil(-0.5::float), ceil(0.5::float), ceiling(0.5::float), ceil(0.1::decimal), ceiling (-0.9::decimal)
----
-0 1 1 1 0
query RR
SELECT cos(-0.5), cos(0.5)
----
0.877582561890373 0.877582561890373
query RRR
SELECT sin(-1.0), sin(0.0), sin(1.0)
----
-0.841470984807897 0 0.841470984807897
query RR
SELECT degrees(-0.5), degrees(0.5)
----
-28.6478897565412 28.6478897565412
subtest extra_float_digits_3
statement ok
SET extra_float_digits = 3
query RR
SELECT acos(-0.5), round(acos(0.5), 15)
----
2.0943951023931957 1.047197551196598
query RR
SELECT cot(-0.5), cot(0.5)
----
-1.830487721712452 1.830487721712452
query RRR
SELECT asin(-0.5), asin(0.5), asin(1.5)
----
-0.5235987755982989 0.5235987755982989 NaN
query RR
SELECT atan(-0.5), atan(0.5)
----
-0.4636476090008061 0.4636476090008061
query RR
SELECT atan2(-10.0, 5.0), atan2(10.0, 5.0)
----
-1.1071487177940904 1.1071487177940904
query RRR
SELECT cbrt(-1.0::float), round(cbrt(27.0::float), 15), cbrt(19.3::decimal)
----
-1 3 2.6823725926296729544
query RRRRR
SELECT ceil(-0.5::float), ceil(0.5::float), ceiling(0.5::float), ceil(0.1::decimal), ceiling(-0.9::decimal)
----
-0 1 1 1 0
query RR
SELECT cos(-0.5), cos(0.5)
----
0.8775825618903728 0.8775825618903728
query RRR
SELECT sin(-1.0), sin(0.0), sin(1.0)
----
-0.8414709848078965 0 0.8414709848078965
query RR
SELECT degrees(-0.5), degrees(0.5)
----
-28.64788975654116 28.64788975654116
statement ok
SET extra_float_digits = 0
subtest other_tests
query IIII
SELECT div(-1::int, 2::int), div(1::int, 2::int), div(9::int, 4::int), div(-9::int, 4::int)
----
0 0 2 -2
query RRRRRR
SELECT div(-1.0::float, 2.0), div(1.0::float, 2.0), div(9.0::float, 4.0), div(-9.0::float, 4.0), div(1.0::float, 0.0), div(1111.0::decimal, 9.44)
----
-0 0 2 -2 +Inf 117
query error div\(\): division by zero
SELECT div(1.0::decimal, 0.0::decimal)
query error div\(\): division by zero
SELECT div(1::int, 0::int)
# math.Exp(1.0) returns different results on amd64 vs arm64.
# Round to make this test consistent across archs.
# See https://github.com/golang/go/issues/20319.
query RRR
SELECT exp(-1.0::float), round(exp(1.0::float), 13), exp(2.0::decimal)
----
0.367879441171442 2.718281828459 7.3890560989306502272
query error exp\(\): overflow
SELECT exp(1e2000::decimal)
query RRR
SELECT floor(-1.5::float), floor(1.5::float), floor(9.123456789::decimal)
----
-2 1 9
query BBBBBB
SELECT 1::FLOAT IS NAN, 1::FLOAT IS NOT NAN, isnan(1::FLOAT), 'NaN'::FLOAT IS NAN, 'NaN'::FLOAT IS NOT NAN, isnan('NaN'::FLOAT)
----
false true false true false true
query RRR
SELECT ln(-2.0::float), ln(2.0::float), ln(2.5::decimal)
----
NaN 0.693147180559945 0.91629073187415506518
query error cannot take logarithm of a negative number
SELECT ln(-100.000::decimal)
query error cannot take logarithm of zero
SELECT ln(0::decimal)
query RR
SELECT log(10.0::float), log(100.000::decimal)
----
1 2.0000000000000000000
query error cannot take logarithm of a negative number
SELECT log(-100.000::decimal)
query error cannot take logarithm of zero
SELECT log(0::decimal)
query RRIR
SELECT mod(5.0::float, 2.0), mod(1.0::float, 0.0), mod(5, 2), mod(19.3::decimal, 2)
----
1 NaN 1 1.3
# mod returns the same results as PostgreSQL 9.4.4
# in tests below (except for the error message).
query error mod\(\): zero modulus
SELECT mod(5, 0)
query error mod\(\): zero modulus
SELECT mod(5::decimal, 0::decimal)
query II
SELECT mod(-100, -8), mod(-100, 8)
----
-4 -4
query I
SELECT mod(-9223372036854775808, 3)
----
-2
query I
SELECT mod(-9223372036854775808, -1)
----
0
query I
SELECT mod(9223372036854775807, -1)
----
0
query I
SELECT mod(9223372036854775807, -2)
----
1
query I
SELECT mod(9223372036854775807, 1)
----
0
query I
SELECT mod(9223372036854775807, 2)
----
1
query I
SELECT mod(9223372036854775807, 4)
----
3
# div and mod are a logical pair
query R
SELECT div(9.0::float, 2.0) * 2.0 + mod(9.0::float, 2.0)
----
9
query R
SELECT div(9.0::float, -2.0) * -2.0 + mod(9.0::float, -2.0)
----
9
query R
SELECT div(-9.0::float, 2.0) * 2.0 + mod(-9.0::float, 2.0)
----
-9
query R
SELECT div(-9.0::float, -2.0) * -2.0 + mod(-9.0::float, -2.0)
----
-9
query R
SELECT pi()
----
3.14159265358979
query II
SELECT pow(-2::int, 3::int), pow(2::int, 3::int)
----
-8 8
statement error integer out of range
SELECT pow(2::int, -3::int)
query III
SELECT pow(0::int, 3::int), pow(3::int, 0::int), pow(-3::int, 0::int)
----
0 1 1
statement error integer out of range
SELECT pow(0::int, -3::int)
statement error invalid operation
SELECT pow(0::int, 0::int)
query RRR
SELECT pow(-3.0::float, 2.0), power(3.0::float, 2.0), pow(5.0::decimal, 2.0)
----
9 9 25.00
query R
SELECT pow(CAST (pi() AS DECIMAL), DECIMAL '2.0')
----
9.8696044010893571205
query R
SELECT power(0::decimal, -1)
----
Infinity
statement error invalid operation
SELECT power(-1, -.1)
query RR
SELECT radians(-45.0), radians(45.0)
----
-0.785398163397448 0.785398163397448
query error invalid operation
SELECT round(123.456::float, -2438602134409251682)
query RRR
SELECT round(4.2::float, 0), round(4.2::float, 10), round(4.22222222::decimal, 3)
----
4 4.2 4.222
query R
SELECT round(1e-308::float, 324)
----
1e-308
# round to nearest even
query RRRR
SELECT round(-2.5::float, 0), round(-1.5::float, 0), round(1.5::float, 0), round(2.5::float, 0)
----
-2 -2 2 2
query RRRRRR
SELECT round(-2.5::float), round(-1.5::float), round(-0.0::float), round(0.0::float), round(1.5::float), round(2.5::float)
----
-2 -2 -0 0 2 2
# some edge cases: denormal, 0.5-epsilon, 0.5+epsilon, 1 bit fractions, 1 bit fraction rounding to 0 bit fraction, large integer
query RRRRRRR
SELECT round(1.390671161567e-309::float), round(0.49999999999999994::float), round(0.5000000000000001::float), round(2251799813685249.5::float), round(2251799813685250.5::float), round(4503599627370495.5::float), round(4503599627370497::float)
----
0 0 1 2.25179981368525e+15 2.25179981368525e+15 4.5035996273705e+15 4.5035996273705e+15
# round up for decimals
# These results are indeed different than floats. Compare with postgres.
# Float rounding uses banker, decimal rounding uses half away from zero.
query RRRR
SELECT round(-2.5::decimal, 0), round(-1.5::decimal, 0), round(1.5::decimal, 0), round(2.5::decimal, 0)
----
-3 -2 2 3
query RRRRR
SELECT round(-2.5::decimal, 3), round(-1.5::decimal, 3), round(0.0::decimal, 3), round(1.5::decimal, 3), round(2.5::decimal, 3)
----
-2.500 -1.500 0.000 1.500 2.500
query RRRRR
SELECT round(-2.5::decimal), round(-1.5::decimal), round(0.0::decimal), round(1.5::decimal), round(2.5::decimal)
----
-3 -2 0 2 3
subtest round_max_prec
# Test rounding to 14 digits, because the logic test itself
# formats floats rounded to 15 digits behind the decimal point.
statement ok
SET extra_float_digits = 3
query RRR
SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.12345678901234567890, 14)
----
-2.12346 2.12346 2.12345678901235
query RR
SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1)
----
-1.7976931348623157e+308 1.7976931348623157e+308
query RR
SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303)
----
-1.79769e+308 1.79769e+308
query RR
SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308)
----
-1e+308 1e+308
query RRRR
SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17)
----
1.2345678901234567 1.234567890123457 1.2345678901234567 1.2345678901234567
statement ok
SET extra_float_digits = 0
subtest round_low_prec
statement ok
SET extra_float_digits = -6
query RRR
SELECT round(-2.123456789, 5), round(2.123456789, 5), round(2.12345678901234567890, 14)
----
-2.12346 2.12346 2.12345678901235
query RR
SELECT round(-1.7976931348623157e+308::float, 1), round(1.7976931348623157e+308::float, 1)
----
-1.79769313e+308 1.79769313e+308
query RR
SELECT round(-1.7976931348623157e+308::float, -303), round(1.7976931348623157e+308::float, -303)
----
-1.79769e+308 1.79769e+308
query RR
SELECT round(-1.23456789e+308::float, -308), round(1.23456789e+308::float, -308)
----
-1e+308 1e+308
query RRRR
SELECT 1.234567890123456789::float, round(1.234567890123456789::float, 15), round(1.234567890123456789::float, 16), round(1.234567890123456789::float, 17)
----
1.23456789 1.23456789 1.23456789 1.23456789
statement ok
SET extra_float_digits = 0
subtest more_round_tests
query RR
SELECT round(-1.7976931348623157e-308::float, 1), round(1.7976931348623157e-308::float, 1)
----
-0 0
query RRR
SELECT round(123.456::float, -1), round(123.456::float, -2), round(123.456::float, -3)
----
120 100 0
query RRRR
SELECT round(123.456::decimal, -1), round(123.456::decimal, -2), round(123.456::decimal, -3), round(123.456::decimal, -200)
----
1.2E+2 1E+2 0E+3 0E+200
query RRRR
SELECT round('nan'::decimal), round('nan'::decimal, 1), round('nan'::float), round('nan'::float, 1)