How to get substring from column which contains records for filter and group by clause in AWS Redshift database.
I have table with records like:
Table_Id
@JonScott, @AlexYes and other pals who struggle with similar kinda situations.
I found more better approach other than suggested by @AlexYes.
What I did, I flatter category column which result individual records. Which I can further process.
Query:
select row_number() over(order by 1) as r1,
to_char(timestamptz 'epoch' + date_time * interval '1 second', 'yyyy-mm-dd') AS DAY,
split_part(categories, ';', numbers.n) as catg,
value
from
join numbers
on numbers.n <= regexp_count(category_string, ';') + 1
Explanation:
Two functions are useful here: first, the split_part function, which takes a string, splits it on ';' delimiter, and returns the first, second, ... , nth value specified from the split string; second, regexp_count, which tells us how many times a particular pattern is found in our string.
- 热议问题