EXAMPLE:
id core primary secondary
101 4355|6755 4355|7866
102 8566|6755 8566 8566
```````````````````````````````````````````````````````````````````````````````
I need to split the data into another table. One with only codes and indicators. All the codes should be in one column under codes and their respective codes as an indicator in other columns as below:
``````````````````````````````````````````````````````````````````````````
id codes core_ind primary_ind secondary_ind
101 4355 Y Y
101 6755 Y
101 7866 Y
102 8566 Y Y Y
102 6755 Y
I am able to split the columns using lateral but not sure how to put the indicators the their respective columns. Can you suggest anything? Below is the code I used for splitting. Using this code I am able to put all the codes and id's under their respective columns. Now, I need to put the indicators I mentioned above
SELECT id, c.value::varchar AS codes
FROM table
,lateral flatten (input => split(core, '|')) c
UNION ALL
SELECT id, d.value::varchar AS codes
FROM table
,lateral flatten (input => split(primary, '|')) d
UNION ALL
SELECT id, e.value::varchar AS codes
FROM table
,lateral flatten (input => split(secondary, '|')) e
Thanks in Advance!!