'How to find 2nd and 3rd occurrence char(,) in column in redshift db?

In redshift i am using below code.but i am getting first special character position only.

SELECT id,regexp_instr(id,',') ,regexp_instr(id,',',2)FROM test



Solution 1:[1]

If you ultimately want the individual field values and not just the position of the commas you can use SPLIT_PART:

select split_part(id, ',', 1) id1,
    split_part(id, ',', 2) id2,
    split_part(id, ',', 3) id3
from (select '5434980cd70ba0c37d0028, 544976cae79548b16810, 55afdbe672450000a01' id);

          id1           |          id2          |         id3
------------------------+-----------------------+----------------------
 5434980cd70ba0c37d0028 |  544976cae79548b16810 |  55afdbe672450000a01
(1 row)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1