类型转换与杂项函数
更新时间:2026-07-24
本页收录类型转换与类型查看,以及二进制数据与文本表示之间的编解码函数。
| 函数 | 别名 | 说明 |
|---|---|---|
arrow_cast |
— | 将值转换为指定的引擎数据类型 |
arrow_typeof |
— | 返回表达式底层数据类型的名称 |
decode |
— | 将字符串中的文本表示解码为二进制数据 |
encode |
— | 将二进制数据编码为文本表示 |
arrow_cast
将值转换为指定的引擎数据类型。
语法:arrow_cast(expression, datatype)
参数:
- expression:要转换的表达式。可以是常量、列或函数,以及任意运算符的组合。
- datatype:要转换到的引擎数据类型名称,以字符串形式给出。格式与
arrow_typeof的返回值相同。
示例:
SQL
1> select arrow_cast(-5, 'Int8') as a,
2 arrow_cast('foo', 'Dictionary(Int32, Utf8)') as b,
3 arrow_cast('bar', 'LargeUtf8') as c,
4 arrow_cast('2023-01-02T12:53:02', 'Timestamp(Microsecond, Some("+08:00"))') as d
5 ;
6+----+-----+-----+---------------------------+
7| a | b | c | d |
8+----+-----+-----+---------------------------+
9| -5 | foo | bar | 2023-01-02T12:53:02+08:00 |
10+----+-----+-----+---------------------------+
arrow_typeof
返回表达式底层数据类型的名称。
语法:arrow_typeof(expression)
参数:
- expression:要求值的表达式。可以是常量、列或函数,以及任意运算符的组合。
示例:
SQL
1> select arrow_typeof('foo'), arrow_typeof(1);
2+---------------------------+------------------------+
3| arrow_typeof(Utf8("foo")) | arrow_typeof(Int64(1)) |
4+---------------------------+------------------------+
5| Utf8 | Int64 |
6+---------------------------+------------------------+
decode
将字符串中的文本表示解码为二进制数据。
语法:decode(expression, format)
参数:
- expression:包含已编码字符串数据的表达式。
- format:与 encode 的参数相同。
相关函数:encode
示例:
SQL
1> SELECT arrow_cast(decode('696e666c7578', 'hex'), 'Utf8');
2+-------------------------------------------------------------------+
3| arrow_cast(decode(Utf8("696e666c7578"),Utf8("hex")),Utf8("Utf8")) |
4+-------------------------------------------------------------------+
5| influx |
6+-------------------------------------------------------------------+
encode
将二进制数据编码为文本表示。
语法:encode(expression, format)
参数:
- expression:包含字符串或二进制数据的表达式。
- format:支持的格式为:
base64、hex。
相关函数:decode
示例:
SQL
1> SELECT encode('influx', 'hex');
2+------------------------------------+
3| encode(Utf8("influx"),Utf8("hex")) |
4+------------------------------------+
5| 696e666c7578 |
6+------------------------------------+
评价此篇文章
