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

Forced Conversion Functions

Table 1 Forced conversion functions

MySQL

GaussDB

Difference

CAST()

Supported, with differences

  • In GaussDB, CAST(expr AS CHAR[(N)] charset_info or CAST(expr AS NCHAR[(N)]) cannot be used to convert character sets.
  • In GaussDB, you can use CAST(expr AS FLOAT[(p)]) or CAST(expr AS DOUBLE) to convert an expression to the one of the floating-point type. MySQL 5.7 does not support this conversion.
  • In GaussDB, CAST(expr AS JSON) cannot be used to convert expressions to JSON.
  • In the CAST nested subquery scenario, if the subquery statement returns the FLOAT type, an accurate value is returned in GaussDB while a distorted value is returned in MySQL 5.7. The same rule applies to the BINARY function implemented using CAST.
    --GaussDB
    m_db=# CREATE TABLE sub_query_table(myfloat float) DISTRIBUTE BY REPLICATION;
    CREATE TABLE
    m_db=# INSERT INTO sub_query_table(myfloat) VALUES (1.23);
    INSERT 0 1
    m_db=# SELECT binary(SELECT myfloat FROM sub_query_table) FROM sub_query_table;
     binary 
    --------
     1.23
    (1 row)
    m_db=# SELECT cast((SELECT myfloat FROM sub_query_table) AS char);
     cast 
    ------
     1.23
    (1 row)
    --MySQL 5.7
    mysql> CREATE TABLE sub_query_table(myfloat float);
    Query OK, 0 rows affected (0.02 sec)
    mysql> INSERT INTO sub_query_table(myfloat) VALUES (1.23);
    Query OK, 1 row affected (0.00 sec)
    mysql> SELECT binary(SELECT myfloat FROM sub_query_table) FROM sub_query_table;
    +-----------------------------------------------+
    | binary(SELECT myfloat FROM sub_query_table)   |
    +-----------------------------------------------+
    | 1.2300000190734863                            |
    +-----------------------------------------------+
    1 row in set (0.00 sec)
    mysql> SELECT cast((SELECT myfloat FROM sub_query_table) AS char);
    +------------------------------------------------------+
    | cast((SELECT myfloat FROM sub_query_table) AS char)  |
    +------------------------------------------------------+
    | 1.2300000190734863                                   |
    +------------------------------------------------------+
    1 row in set (0.00 sec)

CONVERT()

Supported, with differences

  • In GaussDB, CONVERT(expr, CHAR[(N)] charset_info or CAST(expr, NCHAR[(N)]) cannot be used to convert character sets.
  • In GaussDB, you can use CONVERT(expr, FLOAT[(p)]) or CONVERT(expr, DOUBLE) to convert an expression to the one of the floating-point type. MySQL 5.7 does not support this conversion.
  • In GaussDB, CONVERT(expr, JSON) cannot be used to convert expressions to JSON.