Question:
I would like to divide a long text in multiple rows; there are other questions similar to this one but none of them worked for me. What I haven = 15
:I tried with string_split and substring but I cannot find anything that works. I thought to use something similar to this:
Answer:
You can usegenerate_series()
to accomplish this:message
into words and then figure out how to break them into groups and then reaggregate.I could not figure out how to split on spaces without recursion. I hope you don’t mind that it treats all whitespace as word boundaries:
Edit to add:
Can you please tell me whether the below works in Redshift?
with gs as (
select generate_series as posn
from generate_series(1, 150000, 15)
)
select *, substring(m.message, gs.posn, 15) as split_message
from messages m
join gs
on gs.posn <= greatest(1, length(m.message))
order by m.id, gs.posn
;
[/code]
If you have better answer, please add a comment about this, thank you!