As you can see below I have Name
column. I want to split it by /
and return the value in array.
MyTable
Id | Name |
---|---|
1 | John/Warner/Jacob |
2 | Kol |
If I write a query as
Select Id, Name from MyTable
it will return
{
"id": 1,
"name": "John/Warner/Jacob",
},
{
"id": 2,
"name": "Kol",
},
Which query should I write to get below result ?
{
"id": 1,
"name": ["John", "Warner", "Jacob"],
},
{
"id": 2,
"name": ["Kol"] ,
},
2
Answers
Don’t think you can return an array in the query itself, but you could do this…
Only way to build it as an array would be when processing the result accordingly in whatever language you are using.
You can define a function
split
, which is based on the fact thatsubstring_index(substring_index(name,'/',x),'/',-1)
will return the x-th part of a name when separated by ‘/’.and then do:
output: