I would like to access first 5 elements of an array "ingredients" before UNNESTing the array:
SELECT
TRIM
(REGEXP_REPLACE
(UNNEST
(string_to_array(ingredients, ';'))[1:5], '\S+\%|\s+\(.*?\)','','g'))
FROM products
The "Ingredients" array may contain values such as:
{'1%', 'abc(2%)', 'abcd', ... , N th element}
The code below works fine but I don't know what's wrong with the above code.
SELECT (string_to_array('1,2,3,4',','))[1:3]