- 类别:
半结构化和结构化数据函数 (类型谓词)
IS_<object_type>¶
此函数系列用作布尔谓词,可用于确定在 VARIANT 列中存储的值的数据类型:
- 另请参阅:
一般使用说明¶
所有函数均为一元,将 VARIANT 表达式作为唯一实参。
如果输入为 SQL NULL 或者 VARIANT 表达式包含 null,则所有函数返回 FALSE。
示例¶
这些示例使用 vartab
表(在 PARSE_JSON 示例中创建):
select n, v, typeof(v) from vartab; +---+------------------------+------------+ | N | V | TYPEOF(V) | |---+------------------------+------------| | 1 | null | NULL_VALUE | | 2 | NULL | NULL | | 3 | true | BOOLEAN | | 4 | -17 | INTEGER | | 5 | 123.12 | DECIMAL | | 6 | 1.912000000000000e+02 | DOUBLE | | 7 | "Om ara pa ca na dhih" | VARCHAR | | 8 | [ | ARRAY | | | -1, | | | | 12, | | | | 289, | | | | 2188, | | | | false, | | | | undefined | | | | ] | | | 9 | { | OBJECT | | | "x": "abc", | | | | "y": false, | | | | "z": 10 | | | | } | | +---+------------------------+------------+
在 VARIANT 列 v
包含字符串值的 vartab
表中,计算所有行:
select count(*) from vartab where is_char(v); +----------+ | COUNT(*) | |----------| | 1 | +----------+
在 VARIANT 列 v
包含指定数据类型的 vartab
表中,选择行:
select * from vartab where is_null_value(v); +---+------+ | N | V | |---+------| | 1 | null | +---+------+ select * from vartab where is_boolean(v); +---+------+ | N | V | |---+------| | 3 | true | +---+------+ select * from vartab where is_integer(v); +---+-----+ | N | V | |---+-----| | 4 | -17 | +---+-----+ select * from vartab where is_decimal(v); +---+--------+ | N | V | |---+--------| | 4 | -17 | | 5 | 123.12 | +---+--------+ select * from vartab where is_double(v); +---+-----------------------+ | N | V | |---+-----------------------| | 4 | -17 | | 5 | 123.12 | | 6 | 1.912000000000000e+02 | +---+-----------------------+ select * from vartab where is_varchar(v); +---+------------------------+ | N | V | |---+------------------------| | 7 | "Om ara pa ca na dhih" | +---+------------------------+ select * from vartab where is_array(v); +---+-------------+ | N | V | |---+-------------| | 8 | [ | | | -1, | | | 12, | | | 289, | | | 2188, | | | false, | | | undefined | | | ] | +---+-------------+ select * from vartab where is_object(v); +---+---------------+ | N | V | |---+---------------| | 9 | { | | | "x": "abc", | | | "y": false, | | | "z": 10 | | | } | +---+---------------+