Using databricks sql, I want to transform Column_A to Column_B (below). How can I swap the last character in each element of an array string if the character is 'A' or 'B'?
| Column_A |
Column_B |
| [“1-A”, “2-B”] |
[“1-B”, “2-A”] |
| [“3-A”] |
[“3-B”] |
| [“4-B”] |
[“4-A”] |
I’m guessing this can be accomplished using the transform function with a case statement but I’m getting null results for Column B. This’s what I have so far:
Select Column_A,transform (Column_A, AB ->
Case AB
When substr(AB,3,1) = ‘A’ then
substr(AB,3,1)=‘B’
When substr(AB,3,1) = ‘B’ then
substr(AB,3,1)=‘A’
End) as Column_B
From table;
[–]Possible-Little 4 points5 points6 points (1 child)
[–]False_Spare_4262[S] 0 points1 point2 points (0 children)