tencent cloud

TencentDB for MySQL

Description of Supported Arithmetic Operations

Download
Focus Mode
Font Size
Last updated: 2025-05-09 11:51:18
The read-only analysis engine currently supports most of the arithmetic operations logic in MySQL. However, certain limitations and incompatibilities still exist in specific scenarios. This document outlines the support for arithmetic operations in the read-only analysis engine and lists the type restrictions for input parameters. Any input types or usage methods not explicitly mentioned in this document are not supported.

Arithmetic Operation Use Limits

Integer division: If the result has more than four decimal places, the read-only analysis engine will, by default, truncate the value and retain only the last four decimal places.
Division with decimal type: The number of decimal places in the result will be truncated based on the number of decimal places in the dividend plus 4. For example, in Decimal(9, 1) / Decimal(9, 1), the result will be truncated to 5 decimal places.
Addition, subtraction, multiplication, and division with decimal: If the total length of the result exceeds 65, an out of range error will be reported. This is because the maximum supported length for the Decimal type in the read-only analysis engine is 65.
Mathematical operations between any numeric type and floating-point types (FLOAT, DOUBLE): These operations are subject to precision errors, primarily because floating-point types such as DOUBLE are not strictly precise by design. In practice, MySQL also discourages performing mathematical operations between numeric types and floating-point types.
Arithmetic operations involving non-numeric types: These operations involve implicit type conversion. Due to limitations in the read-only analysis engine's support for the CAST function, certain arithmetic operations may not be supported if the required CAST conversion is not supported. For details on supported CAST conversions, see Description of Supported Type Conversion Functions.

Supported Arithmetic Operations

+ Addition Operator

Syntax: op1 + op2
Supported value types for op1: int, bigint, float, double, and decimal.
Supported value types for op2: int, bigint, float, double, and decimal.

– Subtraction Operator

Syntax: op1 - op2
Supported value types for op1: int, bigint, float, double, and decimal.
Supported value types for op2: int, bigint, float, double, and decimal.

x Multiplication Operator

Syntax: op1 x op2
Supported value types for op1: int, bigint, float, double, and decimal.
Supported value types for op2: int, bigint, float, double, and decimal.

/ Division Operator

Syntax: op1 / op2
Supported value types for op1: int, bigint, float, double, and decimal.
Supported value types for op2: int, bigint, float, double, and decimal.

% Modulo Operator

Syntax: op1 % op2
Supported value types for op1: int, bigint, float, double, and decimal.
Supported value types for op2: int, bigint, float, double, and decimal.

Help and Support

Was this page helpful?

Help us improve! Rate your documentation experience in 5 mins.

Feedback