I am trying to return all results that match a specific regex in Redshift database.
Sample query
WITH aa AS
(SELECT DISTINCT
id,
record,
regexp_substr(record, '(#{2})([A-Z]{2,3})',1,1),
REGEXP_COUNT(record, '(#{2})([A-Z]{2,3})')
FROM table_a)
SELECT
*
FROM aa
The above query returns the first occurrence and the total count of the occurrences.
Is there a way to return all occurrences? Maybe an iteration using a variable that is limited by the count?
regexp_substr(record, '(#{2})([A-Z]{2,3})',1,n)
There is a solution for Oracle with the CONNECT BY LEVEL, but that option seems to be unavailable for Redshift.