数据类型与字面量
更新时间:2026-07-24
表列类型
写入(Line Protocol)的数据模型映射到 SQL 查询中的列类型如下:
| 写入类型 | SQL / 引擎类型 | 说明 |
|---|---|---|
| tag | Dictionary(Int32, Utf8) |
查询中按字符串比较与显示 |
| field(float) | Float64 |
|
| field(integer) | Int64 |
|
| field(uinteger) | UInt64 |
|
| field(string) | Utf8 |
|
| field(boolean) | Boolean |
|
| time | Timestamp(Nanosecond, None) |
纳秒精度,值为 UTC |
可通过 information_schema.columns 查看列类型。以下示例中的 temps 表包含 tag 列 room 和 float field 列 temp:
SQL
1> SELECT table_name, column_name, data_type FROM information_schema.columns WHERE table_name = 'temps';
2+------------+-------------+-----------------------------+
3| table_name | column_name | data_type |
4+------------+-------------+-----------------------------+
5| temps | room | Dictionary(Int32, Utf8) |
6| temps | temp | Float64 |
7| temps | time | Timestamp(Nanosecond, None) |
8+------------+-------------+-----------------------------+
SQL 类型名
表达式与 CAST 中常用的 SQL 类型名及对应的引擎类型:
| SQL 类型名 | 引擎类型 |
|---|---|
BOOLEAN |
Boolean |
TINYINT / SMALLINT / INT、INTEGER / BIGINT |
Int8 / Int16 / Int32 / Int64 |
上述加 UNSIGNED |
UInt8 / UInt16 / UInt32 / UInt64 |
FLOAT / DOUBLE |
Float32 / Float64 |
VARCHAR / CHAR / TEXT / STRING |
Utf8 |
TIMESTAMP |
Timestamp(Nanosecond, None) |
DATE |
Date32 |
TIME |
Time64(Nanosecond) |
INTERVAL '...' |
Interval(MonthDayNano) |
用 arrow_typeof 查看任意表达式的类型,用 arrow_cast 转换到任意引擎类型(见 类型转换与杂项函数)。
字面量
- 数字:
42(整数,Int64)、3.14(浮点,Float64)。 - 字符串:单引号,
'kitchen';内嵌单引号写成''。 - 布尔:
true/false。 - NULL:
NULL。 - 时间日期:
TIMESTAMP '2024-01-01T08:30:00Z'、DATE '2024-05-01'、TIME '08:30:00';timestamp 字符串按 RFC 3339 解析,无时区后缀时按 UTC 解释。 - 时间间隔:
INTERVAL '1 hour'、INTERVAL '1 hour 30 minutes'、INTERVAL '15 seconds'等自然语言形式。
以下示例展示字面量的类型判定:
SQL
1> SELECT arrow_typeof(42), arrow_typeof(3.14), arrow_typeof('text'), arrow_typeof(true);
2+-------------------------+-----------------------------+----------------------------+-----------------------------+
3| arrow_typeof(Int64(42)) | arrow_typeof(Float64(3.14)) | arrow_typeof(Utf8("text")) | arrow_typeof(Boolean(true)) |
4+-------------------------+-----------------------------+----------------------------+-----------------------------+
5| Int64 | Float64 | Utf8 | Boolean |
6+-------------------------+-----------------------------+----------------------------+-----------------------------+
SQL
1> SELECT arrow_typeof(TIMESTAMP '2024-01-01 00:00:00'), arrow_typeof(DATE '2024-01-01'), arrow_typeof(INTERVAL '1 hour');
2+-------------------------------------------+----------------------------------+---------------------------------------------------------------------------------------------------------------+
3| arrow_typeof(Utf8("2024-01-01 00:00:00")) | arrow_typeof(Utf8("2024-01-01")) | arrow_typeof(IntervalMonthDayNano("IntervalMonthDayNano { months: 0, days: 0, nanoseconds: 3600000000000 }")) |
4+-------------------------------------------+----------------------------------+---------------------------------------------------------------------------------------------------------------+
5| Timestamp(Nanosecond, None) | Date32 | Interval(MonthDayNano) |
6+-------------------------------------------+----------------------------------+---------------------------------------------------------------------------------------------------------------+
SQL
1> SELECT TIMESTAMP '2024-01-01T08:30:00Z', DATE '2024-05-01', TIME '08:30:00';
2+------------------------------+--------------------+------------------+
3| Utf8("2024-01-01T08:30:00Z") | Utf8("2024-05-01") | Utf8("08:30:00") |
4+------------------------------+--------------------+------------------+
5| 2024-01-01T08:30:00 | 2024-05-01 | 08:30:00 |
6+------------------------------+--------------------+------------------+
评价此篇文章
