[For #18707] MySQL compatibility: support DIV and MOD operators

This commit is contained in:
spongedc 2021-01-05 13:03:19 +08:00
parent 0b56bec69c
commit 99335563d1
5 changed files with 56 additions and 0 deletions

View File

@ -18,6 +18,8 @@ const char * ParserMultiplicativeExpression::operators[] =
"*", "multiply",
"/", "divide",
"%", "modulo",
"MOD", "modulo",
"DIV", "intDiv",
nullptr
};

View File

@ -81,3 +81,43 @@
-1
-1
-1
-1
0
0
0
0
0
0
0
0
0
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-1
-2
-3
-4
-5
-6
-7
-8
-9
-10
-1
-1
-1
-1
-1
-1
-1
-1
-1
-1

View File

@ -23,3 +23,9 @@ SELECT intDiv(toInt64(number), -1) FROM numbers(1, 10);
SELECT intDivOrZero(toInt64(number), -1) FROM numbers(1, 10);
SELECT intDiv(number, -number) FROM numbers(1, 10);
SELECT intDivOrZero(number, -number) FROM numbers(1, 10);
SELECT -1 DIV number FROM numbers(1, 10);
SELECT toInt32(number) DIV -1 FROM numbers(1, 10);
SELECT toInt64(number) DIV -1 FROM numbers(1, 10);
SELECT number DIV -number FROM numbers(1, 10);
SELECT -1 DIV 0; -- { serverError 153 }

View File

@ -1,3 +1,7 @@
1 -1 1 -1
0.125 -0.125 0.125 -0.125
1 -1 1 -1
1 -1 1 -1
0.125 -0.125 0.125 -0.125
nan
nan

View File

@ -1,3 +1,7 @@
WITH 8.5 AS a, 2.5 AS b SELECT a % b, -a % b, a % -b, -a % -b;
WITH 10.125 AS a, 2.5 AS b SELECT a % b, -a % b, a % -b, -a % -b;
WITH 8.5 AS a, 2.5 AS b SELECT mod(a, b), MOD(-a, b), modulo(a, -b), moduloOrZero(-a, -b);
WITH 8.5 AS a, 2.5 AS b SELECT a MOD b, -a MOD b, a MOD -b, -a MOD -b;
WITH 10.125 AS a, 2.5 AS b SELECT a MOD b, -a MOD b, a MOD -b, -a MOD -b;
SELECT 3.5 % 0;
SELECT 3.5 MOD 0;