nayan_wylde
Esteemed Contributor II

@elgeo Here are two alternatives.

1. Use a recursive CTE

WITH RECURSIVE loop_cte (lstart, lstring) AS (
  SELECT 5 AS lstart, '' AS lstring
  UNION ALL
  SELECT lstart - 1, CONCAT(lstring, 'VSTRING2')
  FROM loop_cte
  WHERE lstart > 1
)
SELECT * FROM loop_cte;

2. you can use pyspark. If you are running the code in notebook.

lstart = 5
lstring = ""
vstring2 = "VSTRING2"

while lstart > 0:
    lstring += vstring2
    lstart -= 1