Split string to rows

Is there a way to convert a string with commas into rows?

It should be possible if you’re using Postgres. See this SO response. It would be easier to help if you could provide more detail:

  • Which database are you using?
  • What version of Redash?
  • What is your end goal?


Sorry for my half info question.

I am using Postgresql DB and Redash version 8.0.0+b32245 (a16f551e)

So I tried to use to “unnest with string to array” and “regexp_split_to_table” but both the time it popped me an error.

  1. unnest code:
    SELECT t.job_code, s.token
    FROM query_3397 t, unnest ( string_to_array(t.Stages,’,’)) s(token)
    WHERE t.stages IS NOT ‘-’

Error: " Error running query: near “(”: syntax error"

  1. regexp_split_to_table code:
    SELECT t.job_code,
    regexp_split_to_table(t.stages, ‘,’) AS new_stages
    FROM query_3397 t
    WHERE t.stages IS NOT ‘-’

Error: " Error running query: no such function: regexp_split_to_table"

This is how my data looks like
Job Code Stages
NEAFU_10 Edit, Miscellaneous

I want it to look like as the below table
Job Code Stages
NEAFU_10 Edit
NEAFU_10 Miscellaneous

@susodapop: Can you check this please?

The error message is pretty clear: there’s a syntax error in the first example. And in the second, your version of Postgres doesn’t have those functions available. They were added to Postgres in version 8.3. Which version are you using?

Without them you won’t be able to split out values in that way.