点击之家;列有多个 IP 地址的列出 IP 地址的问题
Clickhouse; Issues listing ip addresses where the column has multiple ip addresses
我正在尝试在 Clickhouse Table 中获取我们所有用户的 IPv4 地址列表。由于我们的一些用户有多个用逗号分隔的 IPv4 地址,我创建了这个查询:
SELECT
IF(ip LIKE '%,%', arrayElement(splitByChar(',', ip), 1), ip) AS ip
FROM users
但它给了我这个错误:嵌套类型 Array(String) 不能在 Nullable 类型中。
是否可以像这样只 select 字符串的一部分?
考虑使用 assumeNotNull-函数:
SELECT ips IS NULL ? NULL : IF(ips LIKE '%,%', splitByChar(',', assumeNotNull(ips))[1], ips) AS ip
FROM
(
/* Emulate the test dataset. */
SELECT arrayJoin([NULL, '', '1.1.1.1', '2.2.2.2,3.3.3.3']) AS ips
)
/*
┌─ip──────┐
│ ᴺᵁᴸᴸ │
│ │
│ 1.1.1.1 │
│ 2.2.2.2 │
└─────────┘
*/
SELECT ips IS NULL ? NULL : splitByChar(',', assumeNotNull(ips))[1] AS ip
FROM
(
SELECT arrayJoin([NULL, '', '1.1.1.1', '2.2.2.2,3.3.3.3']) AS ips
)
/*
┌─ip──────┐
│ ᴺᵁᴸᴸ │
│ │
│ 1.1.1.1 │
│ 2.2.2.2 │
└─────────┘
*/
我正在尝试在 Clickhouse Table 中获取我们所有用户的 IPv4 地址列表。由于我们的一些用户有多个用逗号分隔的 IPv4 地址,我创建了这个查询:
SELECT
IF(ip LIKE '%,%', arrayElement(splitByChar(',', ip), 1), ip) AS ip
FROM users
但它给了我这个错误:嵌套类型 Array(String) 不能在 Nullable 类型中。
是否可以像这样只 select 字符串的一部分?
考虑使用 assumeNotNull-函数:
SELECT ips IS NULL ? NULL : IF(ips LIKE '%,%', splitByChar(',', assumeNotNull(ips))[1], ips) AS ip
FROM
(
/* Emulate the test dataset. */
SELECT arrayJoin([NULL, '', '1.1.1.1', '2.2.2.2,3.3.3.3']) AS ips
)
/*
┌─ip──────┐
│ ᴺᵁᴸᴸ │
│ │
│ 1.1.1.1 │
│ 2.2.2.2 │
└─────────┘
*/
SELECT ips IS NULL ? NULL : splitByChar(',', assumeNotNull(ips))[1] AS ip
FROM
(
SELECT arrayJoin([NULL, '', '1.1.1.1', '2.2.2.2,3.3.3.3']) AS ips
)
/*
┌─ip──────┐
│ ᴺᵁᴸᴸ │
│ │
│ 1.1.1.1 │
│ 2.2.2.2 │
└─────────┘
*/