HomeMogDBMogDB StackUqbar
v5.0

Documentation:v5.0

Supported Versions:

Other Versions:

Type Conversion Functions

Type Conversion Functions

  • cast(x as y)

    Description: Converts x into the type specified by y. If the target data type is char, the data type is converted to varchar in the case of dolphin.b_compatibility_mode=on. Otherwise, the data type is still char.

    Example:

    MogDB=# set dolphin.b_compatibility_mode=on;
    
    MogDB=# SELECT cast('abc' as char(10));
     varchar
    ---------
     abc
    (1 row)
    
    MogDB=# SELECT dolphin.b_compatibility_mode=off;
    
    MogDB=# SELECT cast('abc' as char(10));
       bpchar
    ------------
     abc
    (1 row)

In subsequent development, the extended CAST function includes the conversion from money to unsigned and from timestamp to unsigned.

CREATE CAST (timestamp AS uint8) WITH FUNCTION timestamp_uint8(timestamp) AS ASSIGNMENT;
CREATE CAST (money AS uint8) WITH FUNCTION cash_uint(money) AS ASSIGNMENT;

Compatibility

The CREATE CAST instruction complies with the SQL standard. Except that the SQL does not have extra parameters that can be forcibly converted to binary types or implement functions.

MogDB=# SELECT CAST('$2'::money as unsigned);
  uint8
  -------
  2
  (1 row)
MogDB=# SELECT CAST(CURRENT_TIMESTAMP::TIMESTAMP AS UNSIGNED);
  current_timestamp
  -------------------
  20230103023621
  (1 row)
Copyright © 2011-2024 www.enmotech.com All rights reserved.