select name, (regexp_split_to_array(name, '')) from table
结果是{a,b,c,d,e}
。是否可以将其拆分为单个行并按名称分组,使其看起来像:
a 1
b 2
c 3
d 4
e 5
答案 0 :(得分:0)
您正在寻找sketch功能:
select name, unnest(regexp_split_to_array(name, '')) from table
答案 1 :(得分:0)
将unnest()
与row_number()
window function:
if (calcLineSum(a[i], 0, 0) == calcLineSum(a[i + 1], 0, 0))
结果:
WITH test_table(name) AS ( VALUES
('abcde')
)
SELECT *,row_number() OVER () AS row FROM (
SELECT unnest(regexp_split_to_array(name,'')) AS name FROM test_table
) t;
在SO上也有很好的答案:
答案 2 :(得分:0)
如果您使用的是9.4或更高版本,则可以使用with ordinality
:
SELECT name, u.*
FROM the_table
cross join lateral unnest(regexp_split_to_array(name,'')) with ordinality as u(ch, nr)