首页 > 解决方案 > Trino 实现了类似 regexp_split_to_table() 的函数?

问题描述

每个人,

我是 Trino 的新手,我发现 Trinoregexp_split_to_table()中没有像 GreenPlum 或 PostgreSQL 那样的功能。我该如何处理?

select regexp_split_to_table( sensor_type, E',+' ) as type from hydrology.device_info;

标签: sqlsplithivetrino

解决方案


regexp_split(string, pattern)函数,返回数组,可以取消嵌套

演示:

select s.str as original_str, u.str as exploded_value
from
(select 'one,two,,,three' as str)s
cross join unnest(regexp_split(s.str,',+')) as u(str)

结果:

original_str     exploded_value 
one,two,,,three  one
one,two,,,three  two
one,two,,,three  three

推荐阅读