Updated on 2025-06-30 GMT+08:00

Arithmetic Functions

Table 1 Arithmetic functions

Function

Differences Compared with MySQL

ABS()

-

ACOS()

-

ASIN()

-

ATAN()

-

ATAN2()

-

CEILING()

In some scenarios, the return type of the function in GaussDB is different from that in MySQL. Therefore, table columns generated by CREATE TABLE AS compared to MySQL.

  • If the input parameter is of the BIGINT or BIGINT UNSIGNED type and its value contains 20 or more characters (including the sign bit), GaussDB returns an integer, whereas MySQL 5.7 returns a decimal. For example:
    SET m_format_behavior_compat_options='enable_precision_decimal';
    CREATE TABLE tt AS SELECT ceiling(-9223372036854775808);
    DESC tt;

    The return type of MySQL table columns is DECIMAL(16,0).

    The return type of GaussDB table columns is BIGINT(17).

  • If the input parameter is of the NUMERIC type, the return type may be different from that in MySQL. If the parameter is a constant or table column, the same type as that in MySQL 5.7 is returned. For other types of input parameters, such as nested input parameters, the results are different. GaussDB returns the result of the NUMERIC type, whereas MySQL may return an integer. For example:
    SET m_format_behavior_compat_options='enable_precision_decimal';
    CREATE TABLE t AS SELECT ceiling(abs(5.5));
    DESC t;

    The return type of MySQL table columns is INT(4).

    The return type of GaussDB table columns is DECIMAL(3,0).

CEIL()

FLOOR()

COS()

-

DEGREES()

-

EXP()

-

LN()

-

LOG()

-

LOG10()

-

LOG2()

-

PI()

When the precision transfer function is disabled, that is, m_format_behavior_compat_options is not set to enable_precision_decimal, the returned value of the PI function is rounded off to six decimal places in MySQL, but is rounded off to 15 decimal places in GaussDB.

POW()

-

POWER()

-

RAND()

-

SIGN()

-

SIN()

-

SQRT()

-

TAN()

-

TRUNCATE()

-

CRC32()

When the length of the inserted string of the BINARY type is less than the target length, the padding characters in GaussDB are different from those in MySQL. Therefore, when the input parameter is of the BINARY type, the function result in GaussDB is different from that in MySQL.

CONV()

-

COT()

-

RADIANS()

-