Redshift. Convert comma delimited values into rows

后端 未结 8 1175
北恋
北恋 2020-12-01 06:25

I am wondering how to convert comma-delimited values into rows in Redshift. I am afraid that my own solution isn\'t optimal. Please advise. I have table with one of the colu

8条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 06:51

    Late to the party but I got something working (albeit very slow though)

    with nums as (select n::int n
    from
      (select 
          row_number() over (order by true) as n
       from table_with_enough_rows_to_cover_range)
    cross join
      (select 
          max(json_array_length(json_column)) as max_num 
       from table_with_json_column )
    where
      n <= max_num + 1)
    select *, json_extract_array_element_text(json_column,nums.n-1) parsed_json
    from  nums, table_with_json_column
    where json_extract_array_element_text(json_column,nums.n-1) != ''
    and nums.n <= json_array_length(json_column) 
    

    Thanks to answer by Bob Baxley for inspiration

提交回复
热议问题