'How to Split a String and Iterate in Redshift

I'm new to Redshift and I stumbled across a scenario wherein my procedure, I wanted to split a string and iterate it through and do some manipulations in it. I know redshift doesn't support arrays and I want to know how to achieve this in redshift

CREATE OR REPLACE PROCEDURE example(value IN varchar) AS $$
 BEGIN
    --value = 'FIRST, SECOND, THIRD' -> I want to split the string using a comma and iterate through one by one and do some manipulations.
  END;
$$ LANGUAGE plpgsql;

Can Someone guide me through it?

Thanks in Advance,



Solution 1:[1]

You could create a loop of incrementing values, and call SPLIT_PART(), passing in the loop value.

If part is larger than the number of string portions, SPLIT_PART returns an empty string.

Therefore, you would stop the loop if an empty string is returned.

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 John Rotenstein