ITPub博客

首页 > 数据库 > > DorisDB 中的Cast转换函数

DorisDB 中的Cast转换函数

作者:gaokeke123 时间:2022-07-28 10:28:20 0 删除 编辑

函数定义

cast (input as type)

将 input 转换成指定类型(type)的值。如cast (input as BIGINT)将当前列 input 转换为 BIGINT 类型的值。

示例

将常量或表中某列转换为指定类型的值
mysql> select cast (1 as BIGINT);

+-------------------+

CAST(1 AS BIGINT)

+-------------------+

1

+-------------------+

导入数据时转换数据类型
curl --location-trusted -u root: -T ~/user_data/bigint -H "columns: tmp_k1, k1=cast(tmp_k1 as BIGINT)" http://host:port/api/test/bigint/_stream_load

从文本文件导入数据时,系统输入均为字符串。若将值为浮点数的原始数据(如12.34)通过cast函数转换为BIGINT,输出值将为 NULL 。DorisDB目前不会根据小数点截断原始数据以达到取整的效果。如果想强制将这种类型的原始数据转换为整数可参考下面写法。

curl --location-trusted -u root: -T ~/user_data/bigint -H "columns: tmp_k1, k1=cast(cast(tmp_k1 as DOUBLE) as BIGINT)" http://host:port/api/test/bigint/_stream_load

mysql> select cast(cast ("11.2" as double) as bigint);

+----------------------------------------+

CAST(CAST('11.2' AS DOUBLE) AS BIGINT)

+----------------------------------------+

11

+----------------------------------------+

1 row in set (0.00 sec)
————————————————
版权声明:本文为CSDN博主「大数据小王」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_53150969/article/details/124028285

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/26692020/viewspace-3121991/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论
大家好

注册时间:2013-08-14

  • 博文量
    1432
  • 访问量
    31605